how to create $.ajax() for internet explorer
Hallo all , i have wirtten an ajax request to the database server and the return datatype is xml but the IE is unable to render it. but on chrome it works.what could possibly be wrong in my codeActually i get no response for the the server.the element name i am using in my xml doc is ,,, and notthing more. so i really donotttt know where the problem can lie.
$.ajax({
url:'gethint.php',
type:'GET',
data:'p=p' + '&cust_uid=i',
datatype:'xml',
timeout:5000,
error:function(){alert('unable to establish connection to the server ');},
success:function(xml){outputResponseXML(xml);}
});
function outputResponseXML(xml)
{
$('div#me').empty();
var element =$(xml).find('USER');
if(element.length>0)
{
$(xml).find('USER').each(
function(index)
开发者_运维百科 {
var ename= ($(this).find('ENAME').text()=='E')?'':$(this).find('ENAME').text();
var operator=($(this).find('OPERATOR').text()=='E')?'':$(this).find('OPERATOR').text();
var pnr =($(this).find('PNR').text()=='E')?'':$(this).find('PNR').text();
var inr=($(this).find('INR').text()=='E')?'':$(this).find('INR').text();
var $newDiv= $( '<div class=\"items\" id =\"'+inr +'\">'
+ename+'<br/>'+operator+
'<br/>'+ pnr+'</div>');
$newDiv.appendTo('div#me');
});
}
else
{
$('div.me').html('no suggestions found');
}
}
I think the problem is with your "gethint.php" page.
Try to set the header of your PHP page to:
header("Content-Type: text/xml; charset=utf-8", true); header("Cache-Control: no-cache, must-revalidate"); header("Expires: -1"); header("Pragma: no-cache");
And dont forget to print this line in your XML result (must be the first line)
<?xml version="1.0" encoding="utf-8"?>
This guarantee that Internet Explorer will read it correctly.
Clean your cache after the changes.
I'm glad if it helped. Sorry for the bad english. It's not my primary language.
精彩评论