XML received from response is out of format - php

Hi im currently using PHP on a linux server to receive response from a WebService hosted on a Windows server.
I am using the following PHP to read the response :-
while (!feof($socket)) {
$result .= fgets($socket, 4096);
}
fclose($socket);
if ($debug) echo '<pre>',$result,'</pre>';
Apparently when i received the the response it is out of format, with break lines between tags such as the following :-
/9j/4AAQSkZJRgABAQEAYABgAAD/4QBaRXhpZgAATU0AKgAAAAgABQMBAAUAAAABAAAASgMDAAEAAAABAAAAAFEQAAEAAAABAQAAAFERAAQAAAABAAAAAFESAAQAAAABAAAAAAAAAAA
AAYagAACxj
insetead of like these :-
</ResponseHdr><ResGetCustAreaSnapshot><cmc:GetCustAreaSnapshot xmlns:cmc="http://tnb.com.my/CGIS/D/cmc_customermgnt"><cmc:MAP_IMAGE_ZOOM1000>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
apparently even from here i cannot display the tags without using the code block which formats it properly.
would really appreciate it if someone could point me in the right direction on what to look for to fix this problem.
Thank You.

'ow do you look at your debug output: inside a browser or inside a terminal ? Could it be that you simply have the xml like tags ("<...>") in the reply swallowed by visualizing it as html in a browser ?
If that is not the case then I would check the content of the reply on a lower level. Use 'tcpdump' or 'wireshark' to dump the actual content without having to rely on a higher level output.

Try var_dump(htmlspecialchars($result)) instead of echo.

Related

PHP won't receieve POST XML data

I'm building a service backend that is being sent a "delivery report" after successfully sending a SMS to a user.
The report itself is XML POSTed to our "endpoint" with the content-type application/xml.
I'm using Postman to make sure that everything is working correctly. I've made a test using regular JSON and can return the data without issues, however, no matter what I try with XML I basically get no indication that anything is being sent to the server.
(Test with JSON)
(Test with XML)
Here's my simple PHP script:
<?php
header('Content-Type: application/xml; charset=utf-8');
print_r(json_decode(file_get_contents("php://input"), true));
print_r($HTTP_RAW_POST_DATA);
?>
I feel like I've tried everything. Been looking at past issues posted to SO and other places, it simply won't work for me. I'm hoping for some answers that at least points me in the right direction here.
Cheers.
Your trying to json_decode XML data. You should use something like SimpleXML.
Instead of...
print_r(json_decode(file_get_contents("php://input"), true));
You should use ...
$xml = new SimpleXMLElement(file_get_contents("php://input"));
echo $xml->asXML();
You should be able to get the information by (for example)...
echo (string)$xml->id;
json_decode can't read XML, seems like you're trying to parse XML with json_decode. if you want to output the received XML, use echo (or if it's for debugging purposes, use var_dump, eg var_dump(file_get_contents("php://input"));), or if you want to parse the XML, use DOMDocument.

Get Request to an API url

I have signed up to a synonym API.. see the details on this page
I am having trouble implementing this in my php code.
If I copy and paste the link into the web browser, I can see the results no problem.
Instead of typing the word in manually, I wish to have a variable in the link with the relevant word i.e. $variable_with_word_stored as shown below.
http://words.bighugelabs.com/api/2/xxxxxxxx/$variable_with_word_stored/php
//format could be php (I would unserialize)..or json..I could decode it?
Any ideas guys? Thanks.
It sounds like you mean you want the result from calling that webpage and store it in a variable. What you should be looking to do is sending a http get request to that page within the code.
Check out using curl with php, you can send a http request to your requested url, capture the result back and parse it through json_decode
http://php.net/manual/en/curl.examples-basic.php
try it like this, maybe that you dont need curl:
$key = "xxxxxxxx";
$word = "love";
echo file_get_contents("http://words.bighugelabs.com/api/2/$key/$word/php");

How to write response to file using php

I wish to write the response of hitting a given url into the href attribute of an anchor tag using PHP. How can I do this?
Here's an example of what I excpect to happen
mylink.com/getdoc?name=documentA
returns a string as a response:
mylink.com/document2012-03-15.pdf
I need to write this response (using PHP into the href attribute as shown below:
Open Document A
(so the above will be the final source of my page.
I think there are a few ways to do what you want. Not all of them will work exactly as you ask for, but the end result should be the same.
Solution one
My first possible solution was already posted by #shanethehat. You could use file_get_contents to call your PHP script via HTTP and get the response.
Solution two
Another possible solution was suggested in the comments of the post by #YourCommonSense. You could simply include the getdoc script in the PHP script that is generating your HTML file, like this:
$_GET["name"] = "documentA";
echo " Open Document A ";
Solution three
Or you could change the way the getdoc script works. You could use a script more like this:
header("Content-type:application/pdf");
header("Content-Disposition:attachment; filename=\"{$_GET["name"]}\"");
readfile($_GET["name"]);
And you keep your link like this: Open Document A . When getdoc.php is called, it will get the specified file and start a file download.
NOTE: you should probably do some input sanitization with this method (removing slashes, making sure the file ends in .pdf, etc) to make sure someone doesn't try to get a file they're not allowed to get.
That's all I'm coming up with at the moment. There might be a more clever way to do it, but hopefully one of these solutions will do it for you. I would try solution 2 or 3 first, and if they don't work out for you, then go with solution 1.
<?php
//get output from URL
$myfile = file_get_contents('http://mylink.com/getdoc?name=documentA');
?>
Open Document A
How to write response to file using php
Noway.
PHP do not process HTTP requests.
You have to set up your web server to do the rewrite.
There are 100500 questions under mod_rewrite tag, you will find the solution easily.
Note that you may wish to rewrite your url to /getdoc.php?name=document2012-03-15.pdf, not one you mentioned in your question

storing an html in a variable php then echoing it

I'm storing an html in a php variable by using a $_GET method.
This is what I did.
http://myurl.com?html=%3Cdiv%20class=%22invoice-logo%22%20style=%22float:left;margin-bottom:15px;%22%3E%3Cimg%20src=%22https://myurl/account/images/invoice_logo.gif%22%20title=%22New%20Covenant%20Software%22%3E%3C/div%3E%3Cdiv%20style=%22clear:both%22%3E%3C/div%3E%3Ch3%20class=%22invoiceNum%22%20style=%22padding:0px;font-size:25px;%22%3E%3Cstrong%3EInvoice#9368%3Cstrong%3E%3C/strong%3E%3C/strong%3E%3C/h3%3E%3Ctable%20class=%22widefat%22%20style=%22font-size:12px;margin-bottom:6px;width:48%;%22%3E%3Ctbody%3E%3Ctr%3E%3Ctd%20class=%22table_heading%22%20style=%22text-align:left;%22%3EBill%20To%3C/td%3E%3Ctd%20class=%22table_heading%22%20style=%22text-align:left;%22%3EContact%20Us%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22text-align:left;background-color:white;%22%20class=%22table_body%22%3ETravis%20Harris%3Cbr%3ENew%20Covenant%20Software%3Cbr%3E322%20Old%20Mill%20Rd%3Cbr%3ENewmanstown,%20PA%2017073%3C/td%3E%3Ctd%20style=%22text-align:left;background-color:white;%22%20class=%22table_body%22%3ENew%20Covenant%20Software%3Cbr%3E%3Cb%3E%28866%29%20213-6539%3C/b%3E%3Cbr%3E%3Ca%20rel=%22noreferrer%22%20onclick=%22window.open%28%27https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=billing#newcovsoft.com%27,%27Compose%20new%20message%27,%27width=640,height=480%27%29;return%20false%22%20title=%22[GMCP]%20Compose%20a%20new%20mail%20to%20billing#newcovsoft.com%22%20href=%22mailto:billing#newcovsoft.com%22%3Ebilling#newcovsoft.com%3C/a%3E%3Cbr%3E%3C/td%3E%3C/tr%3E%3C/tbody%3E%3C/table%3E%3Cdiv%20style=%22float:right;margin-bottom:5px;%22%3E%3Cstrong%3EDate:%20%3Cspan%20class=%22dateCreated%22%3E12/01/2011%3C/span%3E%20%3Cspan%20style=%22color:#C5D0DD;%22%3E%20|%20%3C/span%3E%20Due%20Date:%20%3Cspan%20class=%22dueDate%22%3E01/01/2012%3C/span%3E%3C/strong%3E%3C/div%3E%3Cdiv%20style=%22clear:both;%22%3E%3C/div%3E%3Cdiv%20id=%22table-invoice-result%22%3E%3Ctable%20class=%22widefat%22%3E%3Ctbody%3E%3Ctr%3E%3Ctd%3EQuantity%3C/td%3E%3Ctd%3EDescription%3C/td%3E%3Ctd%3ERate%3C/td%3E%3Ctd%3EAmount%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E8%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3EROSS%20Server%20Fees:%20TESTING3%20%28December%2016th%202011-January%2015th%202012%29%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E$79.99%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E$639.92%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E12%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3EROSS%20Server%20Fees:%20TESTING3%20%28December%2016th%202011-January%2015th%202012%29%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E$79.99%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E$959.88%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E10%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$799.90%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%3ESales%20Tax%3C/td%3E%3Ctd%20class=%22salestax%22%3E$0.00%3C/td%3E%3Ctd%3E%3C/td%3E%3Ctd%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%3E%3Cstrong%3ETotal%3C/strong%3E%3C/td%3E%3Ctd%20class=%22total%22%20style=%22font-weight:bold;%22%3E$0.00%3C/td%3E%3Ctd%3E%3C/td%3E%3Ctd%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%3E%3C/td%3E%3Ctd%20class=%22date_paid_status%22%20style=%22font-size:%2020pt;%20color:darkblue;%20font-weight:bold;%22%3EPAID%2012/01/2011%3C/td%3E%3Ctd%3E%3C/td%3E%3Ctd%3E%3C/td%3E%3C/tr%3E%3C/tbody%3E%3C/table%3E%3C/div%3E%3Cbr%3E%3Ci%3E*%20Paper%20Checks%20are%20not%20accepted.%20Any%20paper%20checks%20received%20will%20be%20converted%20into%20E-Checks%20and%20destroyed.%3C/i%3E
My problem is if I try to echo this one, I'm not getting all the result. This is how I echo it.
$html = <<<EOD
{$_GET['html']}
EOD;
echo $html;
This are only the results I have when I echoed this:
<div class="invoice-logo" style="float:left;margin-bottom:15px;"><img src="https://myurl/account/images/invoice_logo.gif" title="Test Title"></div><div style="clear:both"></div><h3 class="invoiceNum" style="padding:0px;font-size:25px;"><strong>Invoice
As you can see, it cuts off after the code <strong>Invoice
Any ideas why this is happening. Any help would be greatly appreciated and rewarded!
Thanks!
You are doing something wrong.
HTML is a part of the program code, and shouldn't be sent to and fro between server and client.
Instead of that, only raw data should be recieved from client, then formatted on the server side and then resulting HTML have to be sent to client.
See http://www.boutell.com/newfaq/misc/urllength.html and Is there a limit to the length of a GET request?
You're much better off using curl to get the contents of the URL in PHP (if you're trying to get the HTML from a standard website), or using POST (if you're passing the HTML into the PHP file directly).
If you need the html to be inside a GET request, use base64_encode(). After submitting it, you can decode the html by running base64_decode($_GET['html']).

Can't send content-type: text/xml header from PHP at the same time getting the data from MYSQL

i hope you can cast some light on my problem. I need to do an AJAX / PHP / MYSQL application to display posts and stuff on the page i'm writing.
I only discovered how to do some simple stuff in PHP after taking some mushrooms but that was years ago and now i don't have mushrooms and i'm just stuck!
So here's the problem:
i think i need to send a proper "xml" file through php so the ajax part can take it but: when i try to put the header on top of the php it displays this error:
" Extra content at the end of the document "
When i looked at some tutorials people were using the "header" fearlesly to do such stuff as i want to do and no comments suggested that it didn't work. so why it doesn't work on my local server?
I'm running:
WAMP
Apache 2.2.11
PHP 5.3.0
It also doesn't work on a remote server (PHP 5.3.0) :/
I read all the stuff i could find till 5am and decided to ask you for help for the first time :)
Thank you!
header('content-type: application/xhtml+xml; charset=utf-8');
require_once("allyouneed.php");
require_once("bazingablob.php");
$category=$_GET["category"];
$post_tags=$_GET["post_tags"];
$language=$_GET["language"];
$author=$_GET["author"];
$posts_per_page=$_GET["posts_per_page"];
$current_page=$_GET["current_page"];
$order=$_GET["order"];
$hard_limit=$_GET["hard_limit"];
$show_hidden=$_GET["show_hidden"];*/
$wypluj="";
$wypluj="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
$bazinga_blob = new bazingablob;
if (!$bazinga_blob->connect_to_database())
{
$wypluj.="<IsOK>0</IsOK>";
echo $wypluj;
exit;
}
else
{
$wypluj.="<IsOK>jedziem</IsOK>";
}
$bb_result=$bazinga_blob->get_all_posts($category,$post_tags,$language,$author,$posts_per_page,$current_page,$order,$hard_limit,$show_hidden);
if ($bb_result) //udalo sie cos znalezc w bazie wedlug kryteriow
{
$wypluj.="<Pagination>";
$wypluj.="<CurrentPage>";
$wypluj.=$bazinga_blob->posts_pagination["current_page"];
$wypluj.="</CurrentPage>";
$wypluj.="<LastPage>";
$wypluj.=$bazinga_blob->posts_pagination["last_page"];
$wypluj.="</LastPage>";
$wypluj.="<PostsCount>";
$wypluj.=$bazinga_blob->posts_pagination["posts_count"];
$wypluj.="</PostsCount>";
$wypluj.="</Pagination>";
$wypluj.="<Posts>";
foreach ($bb_result as $item)
{
$wypluj.="<Post>";
$wypluj.="<PostId>".$item->post_id."</PostId>";
$wypluj.="<PostAuthor>".$item->post_author."</PostAuthor>";
$wypluj.="<PostLangId>".$item->post_langid."</PostLangId>";
$wypluj.="<PostSlug>".$item->post_slug."</PostSlug>";
$wypluj.="<PostTitle>".$item->post_title."</PostTitle>";
$wypluj.="<PostGreetingPicture>".$item->post_greeting_picture."</PostGreetingPicture>";
$wypluj.="<PostGreetingVideo>".$item->post_greeting_video."</PostGreetingVideo>";
$wypluj.="<PostGreetingSound>".$item->post_greeting_sound."</PostGreetingSound>";
$wypluj.="<PostShort>".$item->post_short."</PostShort>";
$wypluj.="<PostBody>".$item->post_body."</PostBody>";
$wypluj.="<PostDate>".$item->post_date."</PostDate>";
$wypluj.="<PostPublished>".$item->post_published."</PostPublished>";
$wypluj.="<PostSticky>".$item->post_sticky."</PostSticky>";
$wypluj.="<PostComments>".$item->post_comments."</PostComments>";
$wypluj.="<PostProtected>".$item->post_protected."</PostProtected>";
$wypluj.="</Post>";
}
$wypluj.="</Posts>";
}
echo $wypluj;
The error comes from your browser and indicates that your XML is malformed.
Setting the application/xhtml+xml header tells the browser to process the document as serious XML. XML needs to be "well-formed", i.e. it must not contain any syntax errors. Apparently you do have a syntax error on line 1 at column 73, which makes the browser abort the attempt to process the document.
For this reason it's a pain to hand-code XML, you should really look into a library that takes care of the well-formedness for you, like PHP's own XMLWriter.
Have you validated your XML?
http://friendsofed.infopop.net/4/OpenTopic?a=tpc&s=989094322&f=5283032876&m=4521066061
I'm honestly not sure what you're trying to do with the header, it's not any Ajax method I've ever been taught. The header method you're doing looks just a few lines short of outputting the XML to a download prompt.
Here's my favorite way to do AJAX. Simple, understandable, and quick.
Include Jquery.
Setup your data--whether by form with a Serialize (gets form data into a Javascript Variable) or by just setting some variables as it seems you're doing above.
Send via Jquery Ajax to a separate processing page. The page will receive the data you setup as a $_REQUEST variable, with the method depending on whether you defined it as a POST or not (defaults to a GET)
The processing page --does-- stuff with the REQUEST data and may or may not respond back to the page. This is where you can do stuff like update divs, alert that it worked, etc.
Here's a great tutorial. Focus on the code under "Hello Ajax, Meet Jquery"
If you get yourself any more of those mushrooms, a PHP familiar way to do AJAX is with XAJAX. It allows you to do asynchronous calls to PHP functions. Be aware, though, that the forums are not the most english-friendly and documentation is a bit cryptic.

Categories