Ajax: submit method

Discussion in 'PHP' started by NoamBarz, Jul 26, 2007.

  1. #1
    I'm used to using Ajax, however, the method I use usually requires that I request a php file that queries my database. The thing is that I need to call the php document this way:

    http.open("GET", url, true);

    I would rather use a "post" method instead of the "get" method - makes it easier to pass data to the target page. Is there a way to do so using Ajax?

    Please help.
     
    NoamBarz, Jul 26, 2007 IP
  2. HuggyCT2

    HuggyCT2 Guest

    Messages:
    222
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    You can use a get query quite easily with ajax, something like this.

    
    	var query = "?getvar=" + $get_var;
    	ajaxRequest.open("GET", "script.php" + query, true);
    	ajaxRequest.send(null);
    
    Code (markup):
    Of course change the settings to match yours but it should now let you see how it works.

    Glen
     
    HuggyCT2, Jul 26, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    
    http.open("POST", url, true);
    http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    http.onreadystatechange = your_function;
    http.send('foo=bar&var2=x&etc=so on');
    
    Code (markup):
     
    nico_swd, Jul 26, 2007 IP
    exodus likes this.