IE8和9中Jquery Forms插件的jqXHR响应不正确 [英] Incorrect jqXHR response for Jquery Forms Plugin in IE8 and 9
问题描述
我遇到了一个不寻常的问题,我只能在IE8和9中复制 - 我测试过Safari,Chrome(包括Mac,Firefox(在PC上)和IE8,9和10)。
我有以下代码:
$ $ $''#fileStore_newUpload ').ajaxForm({
beforeSubmit:function(arr,$ form,options){
options.context = $ form;
},
dataType:'xml',
success:function(responseXML,status,jqXHR){
alert(jqXHR.responseText);
var xmlDoc = $ .parseXML(jqXHR.responseText);
$ xml = $( ($ xml.find(uploadSuccess)。text());
alert($(responseXML).find('uploadSuccess').text()); $ b $在所有的浏览器中,除了IE8和9之外,第一个警报(b) )函数引发了以下预期的响应。
<?xml version =1.0encoding =utf-8 ?&G t;
<文件>
< file name =TPHP041879.pdf>
< uploadSuccess> 1< / uploadSuccess>
< filePath> /uploads/2013/09/TPHP0418798.pdf< / filePath>
< / file>
< / files>
但是,在IE8和9中,我得到了一些包含在fileStore_newUpload元件。例如:
< div id =admin_topBanner>
< span>< a href =../ index.php>网站标题< / a>< / span>
....
使用IE9的调试工具,我可以看到响应正文网络请求包含适当的内容,并通过POST发送请求。 (作为此帖子<一>)。我还可以看到响应中有Content-Type application / xml; charset = utf-8set - 这是我认为对于响应是正确的。
我的表格如下:
< form id =fileStore_newUploadaction =<?php echo $ portalOptions [ site_url'];?> /ajax/fileUpload.phpenctype =multipart / form-datamethod =POST>
< label>档案< / label>< br />< input type =filename =fileDocument>< br />
< button type =submitform =fileStore_newUpload>上传档案< / button>
< / form>
我认为这个问题可能是由于 http://bugs.jquery.com/ticket/13388 但我用Jquery 1.9.0,1.9.1和1.10.2并发现所有版本都存在此问题。
我认为这与在此提出的问题相同,但我不太确定:https://stackoverflow.com/questions/17473719/ jquery-form-plugin-the-server-generated-correct-json-response-but-ie-receive
任何帮助将不胜感激。我想我终于搞清楚了这里发生了什么 - 经过几次尝试。
在Internet Explorer 8和9中,有两件事可能导致了这个问题:为了安全起见,我让我的应用将所有X-Frame-Options标题设置为拒绝。我将其更改为SAMEORIGIN以用于我的AJAX响应脚本(仅限于)。 此链接极大地帮助您解决了这个问题。 $ b $对于XML响应,b
我用来解决这个问题的两行PHP是:
$ b $头文件(X-Frame-Options:SAMEORIGIN);
希望这可以帮助别人!
I've got an unusual problem that I've only been able to replicate in IE8 and 9 - I've tested Safari, Chrome (both on a Mac, Firefox (on a PC) and IE8, 9 and 10.
I have the following code:
$('#fileStore_newUpload').ajaxForm({
beforeSubmit: function(arr, $form, options){
options.context = $form;
},
dataType:'xml',
success: function(responseXML,status,jqXHR){
alert(jqXHR.responseText);
var xmlDoc = $.parseXML(jqXHR.responseText);
$xml = $( xmlDoc );
alert($xml.find("uploadSuccess").text());
alert($(responseXML).find('uploadSuccess').text());
}
});
In all browsers but IE8 and 9, the first alert() function brings up the following, expected, response.
<?xml version="1.0" encoding="utf-8" ?>
<files>
<file name="TPHP041879.pdf">
<uploadSuccess>1</uploadSuccess>
<filePath>/uploads/2013/09/TPHP0418798.pdf</filePath>
</file>
</files>
However, in IE8 and 9, I get some of the HTML of the page that contains in the fileStore_newUpload element. For example:
<div id="admin_topBanner">
<span><a href="../index.php">Site Title</a></span>
....
Using IE9's debugging tool, I can see that the response body for the network request contains the appropriate content and the request is sent via POST. (Checked as a result of this post). I can also see that the response has "Content-Type application/xml; charset=utf-8" set - which is what I believe is correct for the response.
My form is as follows:
<form id="fileStore_newUpload" action="<?php echo $portalOptions['site_url']; ?>/ajax/fileUpload.php" enctype="multipart/form-data" method="POST">
<label>File</label><br /><input type="file" name="fileDocument"><br />
<button type="submit" form="fileStore_newUpload">Upload File</button>
</form>
I thought this issue may be as a result of http://bugs.jquery.com/ticket/13388 but I've tested with Jquery 1.9.0, 1.9.1 and 1.10.2 and have found the issue present across all versions.
I think this is the same issue as the one raised here, but I'm not quite sure: https://stackoverflow.com/questions/17473719/jquery-form-plugin-the-server-generates-correct-json-response-but-ie-receives
Any assistance would be appreciated.
I (think I) finally worked out what was going on here - after a few attempts.
Two things may have contributed to this problem in Internet Explorer 8 and 9:
- For security, I had my application set all X-Frame-Options headers to deny. I changed this to SAMEORIGIN for my AJAX response scripts (only). This link helped greatly in working this out.
- IE seemed to go into Quirks mode (as opposed to Standards Mode) for all Content-Type headers other than "Content-type: text/html; charset=utf-8" for the XML responses, which appeared to break IE8 in particular. This breaks JQuery's
The two lines of PHP that I used to rectify this were:
- header("X-Frame-Options: SAMEORIGIN");
- header("Content-type: text/html; charset=utf-8");
Hope this helps someone!
这篇关于IE8和9中Jquery Forms插件的jqXHR响应不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!