简体   繁体   English

从文件://请求时,jQuery Ajax无法访问回调

[英]Jquery Ajax not accessing callback when requested from file://

I make a call from a html file on my PC. 我通过PC上的html文件拨打电话。 And get back illegal character, when it tries to access the callback. 并在尝试访问回调时获取非法字符。 Error code 200, Jquery12133434 was not called. 错误代码200,未调用Jquery12133434。

It works fine from here http://jsfiddle.net/cwatw/ 从这里http://jsfiddle.net/cwatw/

So my question is How would I get this working from a file:// "url" . 所以我的问题是我如何从file://“ url”获得此功能 Which must be the case as it is for a Windows 7 Gadget. 对于Windows 7小工具,一定是这种情况。

Note: I am using JSONP and getting a response. 注意:我正在使用JSONP并得到响应。

Ill be... I just found the solution after days of working on it. 病了...经过几天的努力,我才找到解决方案。

In the Ajax part, add in the following. 在Ajax部分中,添加以下内容。

scriptCharset: "utf-8",

That way it somehow understands the jsonp callback. 这样,它以某种方式理解了jsonp回调。 What baffles me still is why this works without, as long as its not hosted from file:// 令我感到困惑的是,只要没有从file://托管它,为什么没有它就可以工作

Still not showing in the gadget mind, Must not load the same way. 仍未在小工具中显示,不得以相同的方式加载。 :) :)

In your fiddle you are calling data.toSource() on your returned json data . 在您的小提琴中,您正在对返回的json data调用data.toSource() That won't work. 那行不通。 Try 尝试

JSON.stringify(data)

Look like a valid object to me. 在我看来,这是一个有效的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM