Dan*_*umb 12 javascript ajax perl jquery http
我在MSIE8中遇到了一些奇怪的HTTP状态代码问题.
我将HTTP GET发送到以下URL:
/cgi-bin/objectBrowser/snap.pl?file_key=28
Run Code Online (Sandbox Code Playgroud)
从Fiddler,我可以看到我得到以下Raw响应:
HTTP/1.1 302 Found
Date: Fri, 27 May 2011 20:24:38 GMT
Server: Apache/2.2.3 (Red Hat)
Connection: close
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 61
Location: /cgi-bin/objectBrowser/workWithSnap.pl?snapKey=32
Run Code Online (Sandbox Code Playgroud)
这是使用以下Perl生成的:
print $cgi->header( -status => '302 Found' );
print "Location: /cgi-bin/objectBrowser/workWithSnap.pl?snapKey=$snap_key\n\n";
Run Code Online (Sandbox Code Playgroud)
我正在使用jQuery以下列方式访问它:
jQuery.ajax({
type : "GET",
url : "/cgi-bin/objectBrowser/file.pl?pmr=" + request.pmr
+ "&filename=" + request.filename,
statusCode : {
200 : function(file_info) {
if (file_info.status == "parsing") {
jQuery('div#updates').append('<div class="information">No snap yet, but file <i>has</i> been registered already.</div>');
jQuery('div#updates').append('<div class="waiting">Awaiting job completion...</div>');
jQuery.getJSON("/cgi-bin/objectBrowser/job.pl?file_key=" + file_info.file_key, function(job_info) {
poll_for_job_completion(job_info);
});
} else {
jQuery.ajax({
type : "GET",
url : "/cgi-bin/objectBrowser/snap.pl?file_key=" + file_info.file_key,
statusCode : {
302 : function(xhr) {
jQuery('div#updates').append('<div class="information">Redirecting to snap</div>');
alert("302: "+ xhr.responseText);
process_302(xhr.responseText);
}
}
});
}
},
302 : function(xhr) {
alert("302: "+ xhr.responseText);
process_302(xhr.responseText);
},
404 : register_file
}
});
Run Code Online (Sandbox Code Playgroud)
最后,我有以下帮助调试:
jQuery('body').ajaxComplete(function(e,a,o) {
console.log('Event: %o\nXHR: %o\nOptions: %o',e,a,o);
console.log(o.url);
console.log(a.status);
console.log(a.responseText);
});
Run Code Online (Sandbox Code Playgroud)
这一切在Firefox和Chrome中运行良好,但在MSIE中,我通常会得到一个302
响应我的请求的状态snap.pl
,我得到了回复12150
.我发现的最好的打击是在MSDN上,这表明这是ERROR_HTTP_HEADER_NOT_FOUND
......但是标题对我来说很好看.
我无法弄清楚这里出了什么问题......有没有人看到我可能忽略的任何东西?
问题解决了!
该错误是标头生成。
生成的 HTTP 标头中有一个很大的间隙,MSIE8 解释Location
为位于正文中,而不是标头中。
通过使用
print $cgi->redirect( -uri => "/cgi-bin/objectBrowser/workWithSnap.pl?snapKey=$snap_key");
Run Code Online (Sandbox Code Playgroud)
标头已正确创建,我再次获得明智的行为
HTTP/1.1 302 Found
Date: Fri, 27 May 2011 21:00:51 GMT
Server: Apache/2.2.3 (Red Hat)
Location: /cgi-bin/objectBrowser/workWithSnap.pl?snapKey=32
Content-Length: 0
Connection: close
Content-Type: text/plain; charset=UTF-8
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1033 次 |
最近记录: |