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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.