开发者

How to formulate a JSONP request

开发者 https://www.devze.com 2023-04-02 17:53 出处:网络
I am in the process of learning GWT, I am currently facing a problem with making an RPC call to a specific server using JSONP.

I am in the process of learning GWT, I am currently facing a problem with making an RPC call to a specific server using JSONP.

The server I want to communicate with offers JSON-RPC service requiring the request to have a header of {'Content-Type': 'application/json'}, and a body of a regular JSON data, for开发者_StackOverflow example: {"params": ["HelloServer"], "method": "server.greeting", "id": 10}.

I wonder if it possible to make a JSONP request to this server, because I suppose JSONP is the only workaround to the SameOriginPolicy restriction of GWT.


edit: as Darin Dimitrov explained, I guess I have to stick to JSON as the server does not provide JSONP service. The suggested SOP workaround is perfect, it is also suggested here.


I wonder if it possible to make a JSONP request to this server

Not if the server doesn't support it. Here's how the server response need to be modified in order to support JSONP:

someCallback({"params": ["HelloServer"], "method": "server.greeting", "id": 10})

where someCallback is the name of a function which could be specified by the client. If you don't have control over the server and it doesn't support JSONP your only chance is to write a server side script on your domain which will act as a bridge. Then you will send the AJAX request to this script which will delegate it to the remote domain.

0

精彩评论

暂无评论...
验证码 换一张
取 消