简体   繁体   中英

I am doing a JSONP call to backend from javascript function in order to get the response data in json. How to do this from java end?

I am triggering the below crossdomain JSONP call from javascript using ajax:

$.ajax({ 
  url: 'https://xyz.abc.com/xxx/xxx/client', 
  type: 'POST', 
  dataType: 'jsonp', 
  jsonpCallback: 'callback',
  data:{ id: '123456' },
  crossDomain: true,
  contentType: 'application/jsonp'
});

Below are the Query string parameters as seen from the network tab:-

callback=callback&id=123456&_=1498907401152

But due to security and to prevent vulnerability I want to do this call from Java end. How can I do an equivalent JSONP call as posted above from java end? I am using a Struts2 action class.

At Here you read:

JSONP is simply a hack to allow web apps to retrieve data across domains. It could be said that it violates the Same Origin Policy (SOP). The way it works is by using Javascript to insert a "script" element into your page.

So when you want to use Java end, you don't need JSONP. Just do a JSON HTTP POST (like here ) in your action, process response and fill your action and return SUCCESS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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