AJAX w / jQuery无法从请求中获得预期的响应(或任何响应)
||
我没有通过jQuery.ajax API提出的Web服务请求获得预期的响应。 Web服务正在获取请求(在进行jQuery.ajax()调用时,我可以看到它正在处理),并返回正确的XML(从浏览器发出GET请求时,我可以看到期望的XML)。
我正在对Web服务进行AJAX调用,如下所示:
$.ajax({
type: \"GET\",
url: url_to_web_service,
dataType: \"xml\",
success: function (xml) {
// the array of image source locations we\'ll build from the XML
var thumbImgArray = new Array();
// find every image source location and add it to the array
$(xml).find(\"image_src_location\").each(function () {
thumbImgArray.push($(this));
});
// update the scrollable thumbnail images using the new array of image source locations
updateScrollableThumbs($(xml).find(\"indicator\"), thumbImgArray);
},
error: function (xhr, err) {
alert(\"AJAX error function invoked: \\n\\treadyState: \" + xhr.readyState + \"\\n\\tstatus: \" + xhr.status);
$(\'.error\').html(\"responseText: \" + xhr.responseText);
}
});
在发出请求后,我总是得到错误函数,状态为== 4,状态为== 0。
但是,如果我将dataType更改为\“ text / xml \”或\“ text \”,那么我将进入成功函数,但传递给该方法的响应XML数据为空(jqXHR对象的responseXML属性为null )。
发出请求后,Firebug将显示以下内容:
Response Headers
Server Apache-Coyote/1.1
Content-Type text/xml;charset=ISO-8859-1
Content-Language en-US
Content-Length 1326
Date Wed, 25 May 2011 16:02:19 GMT
Request Headers
Host localhost:8080
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17 ( .NET CLR 3.5.30729)
Accept application/xml, text/xml, */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Origin null
它在“响应”选项卡下(表明有效载荷为空?)什么都没有显示,在“ XML”选项卡下,您看到的是:
XML Parsing Error: no element found Location: moz-nullprincipal:{a6fb7963-9b10-464c-a07d-c8e439b98f0d} Line Number 1, Column 1:
^
看来我在jQuery.ajax()调用中做错了,这阻止了XML有效负载被包含在响应中。
谁能建议我应该在哪里寻找错误?
在此先感谢您的帮助。
没有找到相关结果
已邀请:
3 个回复
懊毁暗
森含械
良阑纠苫