Submit a form using JSONP

I want to publish a form with JSONP, is there a possible solution?

I want to submit the form to another domain from jsonp.

+5
source share
3 answers

You cannot do cross-origin POST using JSONP.

However, you can:

+4
source

A JSONP request simply creates a script tag with a function call:

JavaScript:

var head = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script src = 'url_to_post.serverside?callback=callback_function';

var callback_function(response) {
    head.removeChild(script);
    alert(response.abc); // returns def;
};

url_to_post.serverside:

callback_function({"abc": "def"});

, , GET.

:)

+2

$.POST, $.GET, $.AJAX:

$('form').serialize()
+2

All Articles