我只是在玩jQuery并尝试一些应该简单的东西,但它只是不起作用.
$(document).ready(function(){
$.ajax({
url : 'http://soiduplaan.tallinn.ee/',
data : {a : 'p.routes', transport_id : 'tram', t : 'xml', l : 'ee'},
error : function(xhr, stat){
alert('error');
},
success : function(data){
alert('success');
alert(data);
}
});
});
Run Code Online (Sandbox Code Playgroud)
该片段位于test.js文件中,并包含在test.html文件中,该文件在Firefox(3.6)中打开,如file:/// C:/test.html和altough'success'显示数据为空且通过Firebug对XML的响应显示:
X`ML Parsing Error: no element found Location: moz-nullprincipal:{5ac44e50-2cb6-45d1-9cfe-0b999850ecdb} Line Number 1, Column 1:`
Run Code Online (Sandbox Code Playgroud)
或者我尝试添加
dataType : "text"
Run Code Online (Sandbox Code Playgroud)
没有效果,结果仍然作为xml处理(可能是因为响应具有content-type:text/xml; charset = UTF-8).
如果我设置的话,我可以通过Firebug看到响应结果
dataType : "script"
Run Code Online (Sandbox Code Playgroud)
但是因为它实际上不是一个有效的js脚本,它只是失败了,Firebug显示:
invalid regular expression flag t
<?xml version="1.0" encoding="UTF-8"?>..._days><types><type routes="85" city="t
Run Code Online (Sandbox Code Playgroud)
它变得"更好",如果在浏览器中执行上述请求并通过"查看源"复制xml以在此处验证http://www.w3schools.com/Dom/dom_validate.asp它显示"未发现错误",为什么它不会通过xmlhttprequest工作吗?
我究竟做错了什么?
是否有可能以某种方式强制xmlhttprequest的响应被处理为text/plain?
br,伊格斯
PS我已经厌倦了建议的dataType:"html"选项(最初忘了提),但"html"也不起作用,在Firebug中我可以看到有关解析/ moz-nullprincipal的相同错误. …
jquery ×1