Please help i can't return xml data using prototype.
If i use data from direct xml file then it works fine but when i use
ajax request with header content xml it's not working
My code just work on IE but in FF it does not working. My code sample
are given below
If any one already done this kinds of job Please help me as soon as
possible.
var xmlDoc;
function Claulate()
{
var url = 'http://localhost/jibon/jlab/ajaxDirectPrototype/
calculateAjaxFunction.php';
var a = {
empID: 100,
amountTK: 200,
third: 30
};
var pars = new Hash(a).toQueryString();
var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: pars,
onComplete: loadXML
});
}
function loadXML(xmlHttpRequest)
{
// code for IE
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
xmlDoc.loadXML(xmlHttpRequest.responseText);
//xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
//xmlDoc.async=false;
//xmlDoc.load(xmlHttpRequest.responseText);
alert(xmlHttpRequest.responseText);
getmessage();
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation &&
document.implementation.createDocument)
{
alert(xmlHttpRequest.responseText);
//xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
//xmlDoc.loadXML(xmlHttpRequest.responseText);
try {
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load(xmlHttpRequest.responseText);
//xmlDoc.load(xmlHttpRequest.responseText);
//alert(xmlDoc);
xmlDoc.onload=getmessage;
}
catch (e) {
alert("death setting onload\n" + e);
}
}
else
{
alert('Your browser cannot handle this script');
}
}
function getmessage()
{
alert(xmlDoc.getElementsByTagName('title').length);
var x=xmlDoc.getElementsByTagName('title');
for (i=0;i<x.length;i++)
{
alert("Title [" + i + "] :" + x[i].childNodes[0].nodeValue);
}
var x=xmlDoc.getElementsByTagName("book");
alert(x.length);
for(i=0;i<x.length;i++)
{
var attlist=x.item(i).attributes;
var att=attlist.getNamedItem("category");
alert(att.value);
}
}
PHP code:
<?php
header("Content-Type: application/text; charset=utf-8");
$xml='<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="Jewel Category 1">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="Jewel Category 2">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="Jewel Category 3">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="Jewel Category 4">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>';
echo $xml;
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---