• Pre-AJAX methods w/ PHP
    15 replies, posted
I know this is a bit redundant but I would find it of an interest. I've tried to find such methods online and can't decipher them from the book 'AJAX: The complete reference' - it doesn't elaborate on how one receives data from the server (it uses iframes, images and cookies with GET methods). Any help would be greatly appreciated!
[url]http://php4every1.com/tutorials/jquery-ajax-tutorial/[/url]
[QUOTE=compwhizii;27798270][url]http://php4every1.com/tutorials/jquery-ajax-tutorial/[/url][/QUOTE] Sorry, that's not what I asked for. I'm looking for a means to accomplish client/server communication without the use of AJAX. The book displays an example but doesn't elaborate on how to receive the server's response; it users images, cookies, iframes - anything with a .src attribute with the GET method.
[QUOTE=livelonger12;27852908]Sorry, that's not what I asked for. I'm looking for a means to accomplish client/server communication without the use of AJAX. The book displays an example but doesn't elaborate on how to receive the server's response; it users images, cookies, iframes - anything with a .src attribute with the GET method.[/QUOTE] You pretty much just answered your own question. Anything with a SRC attribute can perform a GET request on a resource: [code]<img src="/index.php?data=baconbits" />[/code]You can even change this attribute with JS, and the resource should be requested. Now, albeit being horrible design, this SHOULD work with an iframe - you point the SRC attribute, wait until it loads and fetch it's content (the response). If you're expecting to get response data from the server, I don't see how it could be possible with, say, an image.
[QUOTE=StinkyJoe;27853360]You pretty much just answered your own question. Anything with a SRC attribute can perform a GET request on a resource: [code]<img src="/index.php?data=baconbits" />[/code]You can even change this attribute with JS, and the resource should be requested. Now, albeit being horrible design, this SHOULD work with an iframe - you point the SRC attribute, wait until it loads and fetch it's content (the response). If you're expecting to get response data from the server, I don't see how it could be possible with, say, an image.[/QUOTE] Thanks. I don't understand how to decode the response sent (if) from the server.
Help, please? Apparently one must send the correct headers from the server (no-cache responses) with a standard body, but I don't know how to display the body of the response on the client page without a page refresh.
I have absolutely no idea why you would ever take it upon yourself do bother with something like this.
Explain what you are doing...it makes no sense so far
Apologies. I'm trying to understand the principles of the two-way methods of these: [url]http://ajaxref.com/ch2/[/url] Thus far, I have managed to display a response via an iframe by sending an XML content header with XML content back from the server, but a page refresh still occurs (albeit minute).
[QUOTE=livelonger12;28034731]Apologies. I'm trying to understand the principles of the two-way methods of these: [url]http://ajaxref.com/ch2/[/url] Thus far, I have managed to display a response via an iframe by sending an XML content header with XML content back from the server, but a page refresh still occurs (albeit minute).[/QUOTE] There's no page refresh.
[QUOTE=compwhizii;28036195]There's no page refresh.[/QUOTE] I don't understand this part: [code]function handleResponse(rating, total, average) { /* clear network timeout */ if (timer) clearTimeout(timer); /* get target div */ var target = document.getElementById("resultDiv"); /* indicate vote was made and show result */ target.innerHTML = "Thank you for voting. You rated this a <strong>" + rating + "</strong>. There are <strong>" + total + "</strong> total votes. The average is <strong>" + average + "</strong>. You can see the ratings in the <a href='http://ajaxref.com/ch2/ratings.txt' target='_blank'>ratings file</a>."; }[/code] I.e. how he acquires the variables from an XML document sent from the server without opening the document and parsing it. [editline]14th February 2011[/editline] There's none on that example, but this is the best I've managed thus far... [code] <html> <head> <script type="text/javascript"> var x = 0; var z; function send(a) { x=x+1; var resp = document.getElementById("response"); var iframe = document.createElement("iframe"); iframe.id="" + x + ""; iframe.onload=(resp.innerHTML=resp.innerHTML+"\n"+a); document.body.appendChild(iframe); iframe.src="http://localhost/New%20folder/somepage.php?username=" + a; } </script> </head> <body> <form action="http://localhost/New%20folder/somepage.php" method="get" onsubmit="send(this.a.value)"> <label>Username: <input type="text" id="a" name="a"/></label><br /> <input type="submit" value="submit"> </form><br /> <div id="response" style="position: relative; top: 2%; left: 5%; border: 1px solid black; height: 150px; width: 250px;">Response: <p id="r">&nbsp</p></div><br /> </body> </html> [/code] It still refreshes, albeit extremely fast.
[b]It does not refresh, that is the whole flippin point of AJAX[/b] It opens a connection to the server and grabs the data. [editline]13th February 2011[/editline] [QUOTE=livelonger12;28039769]I.e. how he acquires the variables from an XML document sent from the server without opening the document and parsing it.[/QUOTE] The magic of software [editline]13th February 2011[/editline] [QUOTE=livelonger12;28039769]I don't understand this part: [code]function handleResponse(rating, total, average) { /* clear network timeout */ if (timer) clearTimeout(timer); /* get target div */ var target = document.getElementById("resultDiv"); /* indicate vote was made and show result */ target.innerHTML = "Thank you for voting. You rated this a <strong>" + rating + "</strong>. There are <strong>" + total + "</strong> total votes. The average is <strong>" + average + "</strong>. You can see the ratings in the <a href='http://ajaxref.com/ch2/ratings.txt' target='_blank'>ratings file</a>."; }[/code] [/QUOTE] That's just replacing the stuff on the page [editline]13th February 2011[/editline] If you're using iframes you're going horribly wrong
[QUOTE=compwhizii;28040623][b]It does not refresh, that is the whole flippin point of AJAX[/b] It opens a connection to the server and grabs the data. [editline]13th February 2011[/editline] The magic of software [editline]13th February 2011[/editline] That's just replacing the stuff on the page [editline]13th February 2011[/editline] If you're using iframes you're going horribly wrong[/QUOTE] There's no reason to respond like that, I was only asking for a little help to resolve an issue I had with these methods. And this is not explicitly AJAX (using the XHR). [editline]14th February 2011[/editline] If you test that method on his page, it doesn't initiate a page refresh. Also, I don't understand how he fabricates values from those variables.
The reason he's responding like that is because your endeavor is pointless. It's like attempting to fit logs for wheels instead of the infinitely more conventional tyre, wheel and axle. Use AJAX. Shit's simple.
[QUOTE=Qombat;28045088]The reason he's responding like that is because your endeavor is pointless. It's like attempting to fit logs for wheels instead of the infinitely more conventional tyre, wheel and axle. Use AJAX. Shit's simple.[/QUOTE] Although I agree with you, it's something I feel that I should know before proceeding forward. [editline]15th February 2011[/editline] So, help please?
Sorry, you need to Log In to post a reply to this thread.