drkxgs9358 2011-10-06 17:40
浏览 50
已采纳

在Google App引擎上制作REST API

I have a PHP web application and I want to make a comments section for the same. So, I have decided to do it this way-

Make a Python web application to store comments and retrieve comments from the BigTable. I'd make an AJAX request to store a comment (along with the comment and other parameters) and make an AJAX request to get all the comments from the BigTable in a JSON format (Is it possible to return formatted HTML directly so that I can just replace a div in the parent page which makes the request).

The problem here is that the PHP web application is running on a different domain and I am not sure whether I can make AJAX calls - does this violate the cross-domain security policy. If yes, then how does REST based APIs work - where I can make AJAX requests to and get the JSON in response.

Ideally, I'd like to return formatted HTML directly from GAE. But if that is not possible, I'm fine with returning JSON.

Can this be done? If yes, any pointers on how to make an API like this would be useful. If no, what are the workarounds?

  • 写回答

2条回答 默认 最新

  • dtvdz911959 2011-10-06 19:26
    关注

    Most browsers don't permit cross-origin XHR. The general workaround for this is JSONP, which basically means using a script tag to invoke remote javascript, which passes response data into a local callback.

    There's nothing App Engine-specific about this problem or solution.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序