cancel
Showing results for 
Search instead for 
Did you mean: 

AJAX

decomplexity
Rising Star
Posts: 493
Thanks: 26
Registered: ‎30-07-2007

AJAX

I intend to use some Google features (such as ‘search’) from a home pages server page using AJAX calls from the browser going via a CGI PHP proxy script, and with XSLT translations on the CGI server on the way back.
However, since PN's CGI services run on a different server from the home pages server, I presume that this will prevent browser XMLHttpRequests from working.
If this is so, I appear to have a couple of options:
a. when (e.g.) the ‘search’ button is pressed, serve an intermediate ‘search’ page from the CGI server (instead of the normal server) which in turn issues the XMLHttpRequest
b.  use a <form> POST to get the search string to the CGI server
Questions: will a. work given that the page was not served up as a result of a <link>? And if I use b., it presumably negates advantages of AJAX in that the user’s page will need to be refreshed and any further processing I may wish to do (and I cannot think of any at the moment!) in the browser is impossible
Is there a better way (apart from running the entire website from the CGI server)?
Zen from May 17. PN Business account from 2004 - 2017
2 REPLIES 2
decomplexity
Rising Star
Posts: 493
Thanks: 26
Registered: ‎30-07-2007

Re: AJAX

"Given the new CCGI platform is supposed to be much more reliable..."
Hope so. However, the 'home pages server' part of the site is FTP updated from several locations -  most using non-PN BB ISPs, and (for sensible reasons) PN bar FTPing to the CGI server except from a PN-block IP address
Zen from May 17. PN Business account from 2004 - 2017
Prod_Man
Grafter
Posts: 287
Registered: ‎04-08-2007

Re: AJAX

I see what you are trying to do,
you can do it both ways, just AJAX could be more difficult...
...
<BODY STYLE = "margin: 0px">
<SCRIPT LANGUAGE = "JavaScript" SCR = "MyFunkyScript.js">
<DIV STYLE = "height: 50px width: 100%">
<FORM NAME = "Form1" ACTION = "javascript:ajax_search(document.form1.search.value)">
<INPUT TYPE = "TEXT" NAME = "search">
</FORM>
<DIV ID = ""></DIV>
</BODY>
..
then make your funky script with all the AJAX stuff
you can write a function to change the contents of a DIV Tag
upon receiving all the data from the XML Socket with a POST/GET Method,
I would say post purely for the fact that idiots with just a web browser can't just lynch your script.
You can do it all server side as a PHP/Perl/Similar Script,
I find that way is usually more strait forward and simple,
Ether way if you are making a Proxy script, somewhere you will have to break into a Server Side language.

<?php
if($_SERVER["HTTP_REFERER"] == "http://www.site.com/path/file.html"){
$URL = parse_url($_POST["URL"]);
if($fp=fsockopen($URL["host"],$URL["port"],$en,$es,10)){
$header = 'HTTP Header Here'; // Will require some Ifs to use POST or GET method's
fputs($fp,$header);
while(!feof($fp)){ $data.= fgets($fp); }
//Other code here, if you want to replace links, form methods, image src lines, as to add to users ease of using the Proxy Script etc ... blah blah
echo $data; //return the page code
}else{
echo $en " - " $es;
}
}else{
echo "Stop trying to nick me script!";
}

(Can't remember all the code off heart hopefully gives you a framework if you know some PHP)
YouTube has a very similar way of working,
Look at YouTube's JavaScript Files,
there is one named ajax-xxxxx.js (of some sort)
and one called ui-xxxxx.js
both have what you are after (I think) if your trying to do the Client side stuff
Yeah, the CCGI Space is protected on SSH (Port 22:TCP) from anywhere outside a PlusNet IP Range, but, the FTP is open from anywhere.
Instead, for my site, I chose to make my own admin panel so that I'm not using FTP or similar, in a public place (like at school :P)
Hope that helps.. (sorry if you knew all that or if you already got some of this down)
Jim,