XMLHttpRequest xml响应在jQuery 1.4.1中困扰,如何强制将请求响应处理为纯文本? [英] XMLHttpRequest xml response woes with jQuery 1.4.1, how to force the request response to be processed as plain text?

查看:89
本文介绍了XMLHttpRequest xml响应在jQuery 1.4.1中困扰,如何强制将请求响应处理为纯文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在玩jQuery,并尝试一些应该很简单的方法,但是它却无法正常工作.

I'm just playing around with jQuery and trying something that ought be simple, but it just ain't working.

    $(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);
  }
 });
});

该代码段位于test.js文件中,并包含在test.html文件中,该文件已在Firefox(3.6)中打开,如file:///C:/test.html,并且显示成功"程度,清空并通过Firebug对XML的响应显示:

The snippet is in a test.js file and included in a test.html file which is opened in Firefox (3.6) like file:///C:/test.html and altough 'success' is shown the data is empty and through Firebug the response for XML displays:

X`ML Parsing Error: no element found Location: moz-nullprincipal:{5ac44e50-2cb6-45d1-9cfe-0b999850ecdb} Line Number 1, Column 1:`

或者,我尝试添加

dataType : "text"

无效,结果仍将以xml处理(可能是因为响应的内容类型为:text/xml; charset = UTF-8).

has no effect, the result is still processed as xml (probably because the response has content-type: text/xml; charset=UTF-8).

设置后,我就能通过Firebug查看响应结果

I'm able to see the response results through Firebug if I set

dataType : "script"

但是由于它实际上不是有效的js脚本,因此它只是失败了,Firebug显示:

but then as it isn't actually a valid js script it simply fails, Firebug displays:

    invalid regular expression flag t
<?xml version="1.0" encoding="UTF-8"?>..._days><types><type routes="85" city="t

如果在浏览器中执行上述请求并通过查看源代码"进行复制,则它会变得更好",请在此处复制要验证的xml http://www.w3schools.com/Dom/dom_validate.asp 它显示未发现错误",为什么它不能通过xmlhttprequest起作用?

It gets "better", if do the above request in browser and through "View Source" copy the xml to be validated here http://www.w3schools.com/Dom/dom_validate.asp it displays "no errors found" so why won't it work through xmlhttprequest?

我在做什么错了?

是否有可能以某种方式强制将xmlhttprequest的响应处理为文本/纯文本?

Would it be possible to somehow force the xmlhttprequest's response to be processed as text/plain?

br, 伊吉斯

P.S.我已经厌倦了建议的dataType:"html"选项(最初忘记提及),但是"html"也不起作用,在Firebug中,我可以看到关于parsing/moz-nullprincipal的相同错误.

P.S. I've tired the suggested dataType : "html" option (forgot to mention initially), but the "html" also does not work and in Firebug I can see the same error about parsing/moz-nullprincipal.

另外,提供xml数据的服务由我没有访问权限的第三方控制,或者有这样做的方法,或者我不得不亲吻我的想法再见:(

Also the service providing the xml data is controlled by a third party to which I do not have access, either there is a way to do this or I'll have to kiss my idea goodbye :(

推荐答案

您是否从同一域执行此代码? ( http://soiduplaan.tallinn.ee )

Are you executing this code from the same domain ? (http://soiduplaan.tallinn.ee)

因为不允许使用ajax调用从其他域中获取数据...(除非使用JSONP或脚本数据类型.)

Because you are not allowed to use the ajax calls to fetch data from other domains ... (unless using the JSONP or script datatypes ..)

从远程服务器检索数据时(仅使用脚本或jsonp数据类型才可以),...

When data is retrieved from remote servers (which is only possible using the script or jsonp data types), ...

另一种选择是让jQuery请求一个本地文件,该文件将接收数据服务器端并将其提供给ajax请求.

Tha alternative would be to have jQuery request a local file which would receive the data server-side and serve them to the ajax request..

例如
php: http_post_data
asp: Microsoft.XMLHTTP

for example
php: http_post_data
asp: Microsoft.XMLHTTP

这篇关于XMLHttpRequest xml响应在jQuery 1.4.1中困扰,如何强制将请求响应处理为纯文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆