simple ajax question

E

eddie

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?
 
M

Martin Honnen

eddie said:
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')
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top