0

I'm trying to do a POST RESTful api call from a button on Javascript. The api call is cross domain, so that is a challenge. How do I make this call?

In ajax my call looks like: [I now know that you can't do cross-domain calls from 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 the call looks like:

r = requests.post('http://externenal.website' ,headers={'content-type': 'application/json'}, auth=auth, data=json.dumps(data))

Thanks

Marcus
  • 9,032
  • 11
  • 45
  • 84

1 Answers1

2

You need to use JSONP not json. The problem is that xmlhttprequest has a policy which states that you can't make a request outside of the current site domain. JSONP is a trick to get around this problem.

Be aware that you are breaking a safety policy.

Here's a So post that explains how to do this using JQuery.

Community
  • 1
  • 1
AlexLordThorsen
  • 8,057
  • 5
  • 48
  • 103