jquery - POST RESTful api call from Javascript/Django -
i'm trying post restful api call button on javascript. api call cross domain, challenge. how make call?
in ajax call looks like: [i know can't cross-domain calls ajax]:
$.ajax({ type: 'post', datatype: 'application/json', accept: 'application/json', async: false, username: 'user', password: 'name', url: 'http://exterenal.website', data: { "name": "marcus0.7", "start": 500000, "end": 1361640526000 }, success: function(){alert('done!');}, error:function(){alert('error!')}, });
in python call looks like:
r = requests.post('http://externenal.website' ,headers={'content-type': 'application/json'}, auth=auth, data=json.dumps(data))
thanks
you need use jsonp not json. problem xmlhttprequest has policy states can't make request outside of current site domain. jsonp trick around problem.
be aware breaking safety policy.
Comments
Post a Comment