Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Easy to implement tutorial for AJAX form submit thing without refresh of page...
Old 10-09-2007, 02:07 PM Easy to implement tutorial for AJAX form submit thing without refresh of page...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Hi,

I have seen some stuff about using AJAX to submit forms and things without refreshing or reloading the page like Youtube has for comments and adding to favourites.

etc and i belive VB uses it too when submitting quick posts and editing.

Basically does anyone know a simple tutorial so i can learn how to implement this in my scripts as it will be very useful

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 10-09-2007, 05:07 PM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
Skilled Talker

Posts: 97
Name: Ganesh
Trades: 0
Dan,

The logic is simple.

The things you need are:

1. CGI Script which does the post back for you

2. The client page (which will not be refreshed)

In the CGI script code all you post back events like insert into a database etc... and selecting back the values stored.

With that set.

In the client facing page all you need is a DIV or table with id which preloads with the existing data via AJAX use Sarissa it has built in ajax queries(http://dev.abiss.gr/sarissa/) if you need a simplified one let me know will provide my simplest script.

use the getElementById() function to update the client div or table.

Hope this helps. Good Luck!
__________________
Gather. Search. Compare. Save on Hotel and Flight Prices @
Please login or register to view this content. Registration is FREE
sri_gan is offline
Reply With Quote
View Public Profile
 
Old 10-09-2007, 05:21 PM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
*jaw drop*

Sorry did i mention im a PHPer and dont know much more than document.write javascript wise.

I need simple copy and paste Lol

please
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-09-2007, 05:45 PM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Dan, you won't find any ready made js script for that for the simple reason that ever forms are different.

You will need to dig a bit into javascript for that.
What do you use or plan to use as a JS framework?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-09-2007, 06:26 PM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Im sorry im very big noob with javascript.

can you explain further..


(Also when and why has WMT gone back to the old theme im like WAAA? )
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-10-2007, 03:46 PM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
Skilled Talker

Posts: 97
Name: Ganesh
Trades: 0
Do the Following (common routines):

Put this in file name ajax.js

Code:
//To create an AJAX Object
function createAJAXObj()
{
 var httprequest=false
 if (window.XMLHttpRequest)
 { // if Mozilla, Safari etc
  httprequest=new XMLHttpRequest()
  if (httprequest.overrideMimeType)
   httprequest.overrideMimeType('text/xml')
 }
  else if (window.ActiveXObject)
  { // if IE
   try {
    httprequest=new ActiveXObject("Msxml2.XMLHTTP");
    } 
   catch (e){
     try{
      httprequest=new ActiveXObject("Microsoft.XMLHTTP");
      }
     catch (e){}
     }
  }
return httprequest //return request object
}
 
 
//Common AJAX Reference Object
var ajax=new Object()
ajax.basedomain="<A href="http://"+window.location.hostname">http://"+window.location.hostname
ajax.ajaxobj=createAJAXObj()
ajax.filetype="txt"
ajax.addrandomnumber=0 //Set to 1 or 0. 1 enabled additional IE cache busting
 
 
 
//Get Function
ajax.Get=function(url, parameters, callbackfunc, filetype){
ajax.ajaxobj=createAJAXObj() //recreate ajax object to defeat cache problem in IE
if (ajax.addrandomnumber==1) //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
 if (this.ajaxobj)
 {
 this.filetype=filetype
 this.ajaxobj.onreadystatechange=callbackfunc
 this.ajaxobj.open('GET', url+"?"+parameters, true)
 this.ajaxobj.send(null)
 }
}
 
 
//Post function
ajax.Post=function(url, parameters, callbackfunc, filetype){
ajax.ajaxobj=createAJAXObj() //recreate ajax object to defeat cache problem in IE
 if (this.ajaxobj)
 {
  this.filetype=filetype
  this.ajaxobj.onreadystatechange = callbackfunc;
  this.ajaxobj.open('POST', url, true);
  this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  this.ajaxobj.setRequestHeader("Content-length", parameters.length);
  this.ajaxobj.setRequestHeader("Connection", "close");
  this.ajaxobj.send(parameters);
 }
}
Sample to Initiate Ajax Object (Client HTML)

Code:
<html>
<head><title>some thing of your choice</title>
<script type="text/javascript" src="iiajax.js"> </script>
 
<script>
 
function postSample()
{
ajax.Post('cgi file name','parameter to be sent for post operation',callbackxyz, 'txt')
}
 
//function to handle the post operation ideally this is were the out of cgi is 
//handled.
 
function callbackxyz()
{
   var myajax=ajax.ajaxobj
    var myfiletype=ajax.filetype
    if (myajax.readyState == 4)
    { 
 
         //if request of file completed
        if (myajax.status==200 || window.location.href.indexOf("http")==-1)
         { 
          //update the out put from CGI
          }
   }
}
 
</script>
 
</head>
 
 
 
</html>
__________________
Gather. Search. Compare. Save on Hotel and Flight Prices @
Please login or register to view this content. Registration is FREE
sri_gan is offline
Reply With Quote
View Public Profile
 
Old 10-10-2007, 04:00 PM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Ok thanks alot and i will give tp but could i ask for a example of say a simple form

for instance you enter a number it ads 2 and echos the number. so i can see how it would work?

Thanks alot

--edit---
Sorry i cant give you any i have to spread some around
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-10-2007, 07:54 PM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
Skilled Talker

Posts: 97
Name: Ganesh
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
Ok thanks alot and i will give tp but could i ask for a example of say a simple form

for instance you enter a number it ads 2 and echos the number. so i can see how it would work?

Thanks alot

--edit---
Sorry i cant give you any i have to spread some around
Here is the simplest version:

http://ajax.sys-con.com/read/351875.htm
__________________
Gather. Search. Compare. Save on Hotel and Flight Prices @
Please login or register to view this content. Registration is FREE
sri_gan is offline
Reply With Quote
View Public Profile
 
Old 10-11-2007, 06:47 AM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I will have to remember to look at this when i get home i am at school at the moment.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-11-2007, 04:22 PM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
Skilled Talker

Posts: 97
Name: Ganesh
Trades: 0
Yo Dan!! Does the above link help you?
__________________
Gather. Search. Compare. Save on Hotel and Flight Prices @
Please login or register to view this content. Registration is FREE
sri_gan is offline
Reply With Quote
View Public Profile
 
Old 10-13-2007, 12:09 PM Re: Easy to implement tutorial for AJAX form submit thing without refresh of page...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Sorry took so long

yea could be useful hopefully i will get a better understanding thanks!
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Easy to implement tutorial for AJAX form submit thing without refresh of page...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.48249 seconds with 12 queries