simple ajax question

Discussion in 'Javascript' started by eddie, Nov 8, 2006.

  1. eddie

    eddie Guest

    I have a form. The form submits correctly and the php script GET's the
    ?variables=whatever&variables2=whatever2, but when I try and use AJAX,
    I receive no errors, my innerHTML is changed with the responsetext, but
    my php script never receives the GET variables. Here is the php script:


    <?php

    // Host/IP
    $host = $_REQUEST['host'];

    // Start Port
    $port = $_REQUEST['port'];

    if(empty($host) && empty($port)) { echo "host and port are both
    empty!"; exit(); }

    ?>

    I use an onclick with an img to call the function:
    SetInnerHTMLFromAJAX('connect.php','myobj');

    //ajax.js--------------------------------------

    // Get a browser independent XMLHTTP Object
    function GetXMLHTTP() {
    var XMLHTTP = false;
    if (window.XMLHttpRequest) {
    XMLHTTP = new XMLHttpRequest()
    } else if (window.ActiveXObject) {
    try {
    XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP")
    } catch (e) {
    try {
    XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP")
    } catch (E) {
    XMLHTTP = false;
    }
    }
    }
    return XMLHTTP;
    };


    // Pass a server side response as a javascript function
    function SetInnerHTMLFromAJAX(url, obj_id) {
    var XMLHTTP = new GetXMLHTTP();
    // Send the Request
    if (XMLHTTP) {
    XMLHTTP.onreadystatechange = function stateChange() {
    if (XMLHTTP && XMLHTTP.readyState == 4) {
    // Got something back..
    if (XMLHTTP.status == 200) {
    // Check to see if the response was good
    var response = XMLHTTP.responseText;
    if(debug) {
    alert(response);
    }
    document.getElementById(obj_id).innerHTML = response;
    } else if(debug){
    document.write(XMLHTTP.responseText);
    }
    }
    }
    // open the page
    XMLHTTP.open("GET", url, true);
    // send the data
    XMLHTTP.send(null);
    }
    }

    // end ajax.js


    Anyone have any idea why my ajax is not passing the get variables to
    the php $_REQUEST?
     
    eddie, Nov 8, 2006
    #1
    1. Advertising

  2. eddie wrote:
    > I have a form. The form submits correctly and the php script GET's the
    > ?variables=whatever&variables2=whatever2, but when I try and use AJAX,
    > I receive no errors, my innerHTML is changed with the responsetext, but
    > my php script never receives the GET variables. Here is the php script:


    > I use an onclick with an img to call the function:
    > SetInnerHTMLFromAJAX('connect.php','myobj');


    So here you pass in a relative URL with 'connect.php' that has _no_
    arguments in the query string at all. How do you expect that variables
    are passed to the server if you script does not do that?


    > function SetInnerHTMLFromAJAX(url, obj_id) {



    > XMLHTTP.open("GET", url, true);
    > // send the data
    > XMLHTTP.send(null);


    The comment says "send the data" but for a GET request the data belongs
    in the query string of the URL e.g.
    SetInnerHTMLFromAjax('connect.php?arg=1&arg2=2', 'myobj')

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 8, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dondraper
    Replies:
    2
    Views:
    729
    dondraper
    Jan 27, 2006
  2. minnie
    Replies:
    1
    Views:
    737
    Andrew Thompson
    Dec 13, 2006
  3. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Simple AJAX Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Sep 20, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    615
    =?Utf-8?B?UnlhbiBTbWl0aA==?=
    Sep 20, 2007
  4. Steven

    Very simple AJAX question

    Steven, Nov 19, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    372
    Steven
    Nov 20, 2008
  5. Doug Lerner
    Replies:
    0
    Views:
    91
    Doug Lerner
    Apr 16, 2006
Loading...

Share This Page