GWT Web应用程序试图从PHP获取json [英] GWT web app trying to get json from PHP

查看:129
本文介绍了GWT Web应用程序试图从PHP获取json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GWT应用程序,我正在使用RequestBuilder从我在Fatcow.com服务器上运行的PHP脚本获取GET JSON.它在浏览器中返回的json很好,并且在Charles Web调试代理中返回200的状态,但是在GWT应用程序中,它总是说响应状态为0,并且不给我任何json.当我在一个已知的工作URL上测试我的代码时,它返回200,我得到了我期望的json.另外,我已经有了header('Content-Type:application/json; charset = utf-8');在我的php中,我知道这是一个常见错误.是否有任何理由将无法正常工作?这是PHP的事情,还是我做错了什么?

I have a GWT app and I'm using RequestBuilder get GET some json from a php script I have running on a Fatcow.com server. It returns the json just fine in the browser and returns a 200 status in Charles web debug proxy, but in the GWT app it always says the response status is 0 and doesn't give me any json. When I test my code on a known working URL, it returns 200 and I get the json I expect. Also, I already have header('Content-Type: application/json; charset=utf-8'); in my php, which I know is a common error. Is there any reason this would not be working? Is it a php thing, or am I doing something wrong?

推荐答案

您遇到的是 Same-Origin政策.

CORS 受支持在最新的浏览器中(例外:IE和Opera;将分别在IE 10和Opera 12中提供).

CORS is supported in most recent browsers (exceptions: IE and Opera; will be coming in IE 10 and Opera 12 respectively).

只有可行的替代方法是 JSONP (使用

Only viable alternatives are JSONP (using JsonpRequestBuilder in GWT) or a "proxy" on the same server serving your GWT app.

这篇关于GWT Web应用程序试图从PHP获取json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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