My jQuery/AJAX script posts to a php file in hopes of returning XML. When I print if the data I get all the html source code returned and the xml is not properly parsed in IE 8 or less. The code works in IE 9 and all other browsers. If anyone has a suggesion to what is goin on or a solution to my problem?
我的jQuery / AJAX脚本发布到php文件,希望返回XML。当我打印如果数据我得到所有html源代码返回并且xml未在IE 8或更低版本中正确解析。该代码适用于IE 9和所有其他浏览器。如果有人对我的问题有什么建议或解决我的问题?
jQuery:
jQuery的:
$.post("load-content/", {type: "POST", img: placeholder, dataType: "XML", selection: $(this).html()}, function(xml) {
// format and output result
// alert(placeholder+' && '+$(this).html());
nshow = $("content", xml).text() ;
$("div p.p2").html(
$("content", xml).text()
);
alert("HERE IE 9+ "+xml.length);
});
php:
PHP:
if(isset($_REQUEST["img"]) && isset($_REQUEST["selection"])) {
$xml='<ratings><content>test</content></ratings>';
echo $xml;
*FYI this code is being run in Zencart folder
*仅供参考此代码正在Zencart文件夹中运行
2 个解决方案
#1
1
Solved.
There were two problems here.
解决了。这里有两个问题。
- As the above answer suggested there was a problem with headers.
- 如上面的答案所示,标题存在问题。
-
Again as the answer above suggested there was a problem with the datatype... code for older IE browsers should look something like
再次如上面的答案所示,数据类型存在问题...较旧的IE浏览器的代码应该类似于
$.post("/load-content/", {type: "POST", img: showcase, menuv: aname}, function(response) { ...
#2
0
Actually i think your problem is making the ajax call itself. You are using $.post
but youre supplying the options hash as if it is $.ajax
. The two are different...
实际上我认为你的问题是自己调用ajax。您正在使用$ .post但是您提供的选项哈希就好像它是$ .ajax一样。两者不同......
$.post
takes the url, data, callback and response type as the arguments. You are supplying a hash similar to the one you would supply to $.ajax
as your second argument which is not what it wants.
$ .post将url,data,callback和response类型作为参数。您提供的哈希类似于您将提供给$ .ajax的哈希值作为您的第二个参数,而不是它想要的。
If you are going to use $.post
it shoudl look like this:
如果你打算使用$ .post,它应该是这样的:
$.post("load-content/", {img: placeholder, selction: whatever}, function(), 'xml');
Additionally its not obivous what the contex of your call is... this
may not exist unless this is inside an event handler or jQuery.each
iteration so using selection: $(this).html()
may not make sense.
此外,你的调用的上下文不是很明显...这可能不存在,除非这是在事件处理程序或jQuery.each迭代中,所以使用选择:$(this).html()可能没有意义。
Have you tried setting the proper header for your response and exiting immeadiately?
您是否尝试过为响应设置正确的标题并立即退出?
if(isset($_REQUEST["img"]) && isset($_REQUEST["selection"])) {
header('Content-type: application/xml');
$xml='<ratings><content>test</content></ratings>';
echo $xml;
exit(0);
}
#1
1
Solved.
There were two problems here.
解决了。这里有两个问题。
- As the above answer suggested there was a problem with headers.
- 如上面的答案所示,标题存在问题。
-
Again as the answer above suggested there was a problem with the datatype... code for older IE browsers should look something like
再次如上面的答案所示,数据类型存在问题...较旧的IE浏览器的代码应该类似于
$.post("/load-content/", {type: "POST", img: showcase, menuv: aname}, function(response) { ...
#2
0
Actually i think your problem is making the ajax call itself. You are using $.post
but youre supplying the options hash as if it is $.ajax
. The two are different...
实际上我认为你的问题是自己调用ajax。您正在使用$ .post但是您提供的选项哈希就好像它是$ .ajax一样。两者不同......
$.post
takes the url, data, callback and response type as the arguments. You are supplying a hash similar to the one you would supply to $.ajax
as your second argument which is not what it wants.
$ .post将url,data,callback和response类型作为参数。您提供的哈希类似于您将提供给$ .ajax的哈希值作为您的第二个参数,而不是它想要的。
If you are going to use $.post
it shoudl look like this:
如果你打算使用$ .post,它应该是这样的:
$.post("load-content/", {img: placeholder, selction: whatever}, function(), 'xml');
Additionally its not obivous what the contex of your call is... this
may not exist unless this is inside an event handler or jQuery.each
iteration so using selection: $(this).html()
may not make sense.
此外,你的调用的上下文不是很明显...这可能不存在,除非这是在事件处理程序或jQuery.each迭代中,所以使用选择:$(this).html()可能没有意义。
Have you tried setting the proper header for your response and exiting immeadiately?
您是否尝试过为响应设置正确的标题并立即退出?
if(isset($_REQUEST["img"]) && isset($_REQUEST["selection"])) {
header('Content-type: application/xml');
$xml='<ratings><content>test</content></ratings>';
echo $xml;
exit(0);
}