Echo Ajax
Moderator: General Moderators
Echo Ajax
Hi all,
Currently I am working on a multi-core internet plugin for php and javascript. When it is done it will be able to run functions asynchronously on different computers. The issue is the all-important result ajax call, which temporary saves the result of a function to an xml file. Below is the code:
echo '<script type="application/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>';
echo"<script>var result = eval('".$code."');</script>"; //evaluates the function and stores it in var result
echo'<script>$.get("fxn.php", { r: ""+result, id:""+'.$id.' } );</script>'; //sends the data to the php file to be saved
Note: $id is the identifier of the result
Here is the code from the file that the data is sent to:
$xml = simplexml_load_file("results.xml");
$doc = new SimpleXMLElement($xml->asXML());
$object = $doc->addChild('result');
$object->addAttribute("id",$_GET['id']);
$object->addAttribute("result",$_GET['r']);
$doc->asXML('results.xml');
The problem is it never sends the data to that file. Any help would be much appreciated. Thanks.
Currently I am working on a multi-core internet plugin for php and javascript. When it is done it will be able to run functions asynchronously on different computers. The issue is the all-important result ajax call, which temporary saves the result of a function to an xml file. Below is the code:
echo '<script type="application/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>';
echo"<script>var result = eval('".$code."');</script>"; //evaluates the function and stores it in var result
echo'<script>$.get("fxn.php", { r: ""+result, id:""+'.$id.' } );</script>'; //sends the data to the php file to be saved
Note: $id is the identifier of the result
Here is the code from the file that the data is sent to:
$xml = simplexml_load_file("results.xml");
$doc = new SimpleXMLElement($xml->asXML());
$object = $doc->addChild('result');
$object->addAttribute("id",$_GET['id']);
$object->addAttribute("result",$_GET['r']);
$doc->asXML('results.xml');
The problem is it never sends the data to that file. Any help would be much appreciated. Thanks.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Echo Ajax
What does "multi-core" mean?ggobieski wrote:Currently I am working on a multi-core internet plugin for php and javascript.
Looking at your code, it appears that the XML isn't being saved back to the file. Did you omit that part? By the way, please post your code in
Code: Select all
Re: Echo Ajax
Sorry for the incorrect syntax. Multi-core basically means that multiple computers will be doing the work at the same time. To answer your second question, the code to save the xml is correct – I did not omit anything. The real problem is getting it to send the information to that file. Here I will provide all of the code including the debugging statements for that file:
And once again the code for the echo ajax:
Thanks.
Code: Select all
echo '<script>alert("FXN")</script>'; //should pop up with an alert right?
$xml = simplexml_load_file("results.xml");
$doc = new SimpleXMLElement($xml->asXML());
$object = $doc->addChild('result');
$object->addAttribute("id",$_GET['id']);
$object->addAttribute("result",$_GET['r']);
$doc->asXML('results.xml'); //this statement saves the file
Code: Select all
echo"<script>var result = eval('".$code."');</script>";
echo "<script>alert('Mid');</script>";
echo'<script>$.get("fxn.php", { r: ""+result, id:""+'.$id.' } );</script>';
echo "<script>alert('end');</script>";- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Echo Ajax
I see, yeah. No, that won't pop up an alert. You need to attach an event to the AJAX call with success().
Did you check the XML file to see if the contents are there?
Code: Select all
echo'<script>$.get("fxn.php", { r: ""+result, id:""+'.$id.' } ).success(function() { alert("FXN"); });</script>';Re: Echo Ajax
Yes I checked the xml file and it is unchanged – not updated. I also went back to the call and used your code with the success alert and sure enough no alert. I now know where the problem is, but I don't see any errors. Here is the code that you gave me:
Thanks for the response!
Code: Select all
echo'<script>$.get("fxn.php", { r: ""+result, id:""+'.$id.' } ).success(function() { alert("FXN"); });</script>';- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Echo Ajax
Then you need to do some debugging. Are you sure you typed the file name right? Try adding an error event as shown in the documentation here:
http://api.jquery.com/jQuery.get/#jqxhr-object
http://api.jquery.com/jQuery.get/#jqxhr-object
Re: Echo Ajax
A good tool for trouble shooting AJAX calls is a program for windows called Fiddler (at fiddler2.com). You turn it on, and all browser requests (and results) are passed through it, so you can see the raw data sent to an ajax request and the raw results from it. Can save a lot of time adding debug code to track what is going being sent and received. This is especially true when you are doing AJAX (and form troubleshooting) that uses POST instead of GET, as you can see ALL post AND GET data being sent with the request. If you have a page that is making calls wrong, you can quickly find it.
-Greg
PS, I forget if it auto sets it up or not with current versions, but there is an Add-On for firefox (gives you an icon to turn on/off sending traffice through fiddler, I usually leave it set to "Automatic", so that if the program is running, it uses it.) Oh another hint, don't have facbook open while using it or streaming something like Netflix. fills up the logs like crazy LOL
-Greg
PS, I forget if it auto sets it up or not with current versions, but there is an Add-On for firefox (gives you an icon to turn on/off sending traffice through fiddler, I usually leave it set to "Automatic", so that if the program is running, it uses it.) Oh another hint, don't have facbook open while using it or streaming something like Netflix. fills up the logs like crazy LOL
Re: Echo Ajax
So after much tinkering and using the code from the Jquery site, I finally got it to work! Thanks much.

-
viramkhand
- Forum Newbie
- Posts: 1
- Joined: Sun Aug 07, 2011 10:30 pm
Re: Echo Ajax
hello sir ,
i am from INDIA ,and i want to know the best forum development platform,other than phpBB,in addition i also want to know that in which platform the following site forum is formed:
http://www.pagalguy.com/forum/?ref=mm
http://forum.santabanta.com/
please reply as early as possible
i am from INDIA ,and i want to know the best forum development platform,other than phpBB,in addition i also want to know that in which platform the following site forum is formed:
http://www.pagalguy.com/forum/?ref=mm
http://forum.santabanta.com/
please reply as early as possible
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Echo Ajax
@viramkhand: I don't know that there is necessarily a "best". I haven't personally used any of them. Both of those sites use vBulletin.
In future, if you have a question please create a new thread for it, it's best to keep threads on-topic.
In future, if you have a question please create a new thread for it, it's best to keep threads on-topic.