Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > simple ajax question

Reply
Thread Tools

simple ajax question

 
 
eddie
Guest
Posts: n/a
 
      11-08-2006
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?

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-08-2006
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very simple AJAX question Steven ASP .Net 2 11-20-2008 01:20 PM
Simple AJAX Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 3 09-20-2007 02:18 PM
AJAX IDE and AJAX TOOL--The Release of JoyiStar AJAX WebShop 3 Beta minnie Java 1 12-13-2006 06:29 AM
prototype/ajax really simple Event.observe question Doug Lerner Javascript 0 04-16-2006 11:16 AM
New Question on Simple XML DOM Problem in AJAX Implementation dondraper XML 2 01-27-2006 08:47 PM



Advertisments