Question

I want to enable form Post from another sites.suppose i have one Form in my site and i want to enable that form post for another sites.

i have asp.net web page www.xyx.com\formpost.aspx with field EMail.and i want to enable my page form post.for all any one who post data into my site. like

1)www.test.com\emailpost.php Form Post from this site.

var str = JSON.stringify($('#myForm').serializeObject());
 $.ajax({
              type: 'POST',
              contentType: 'application/json; charset=utf-16',             
              dataType: 'json',
              url: "www.xyx.com/formpost.aspx/SaveCustomerEmail",
              success: function (msg) {
                  alert('done');
              },
              error: function (msg) { 
                alert(JSON.stringify(msg)) }
          });

2)www.test2.com\emailpost.jsp Form Post from this site.

var str = JSON.stringify($('#myForm').serializeObject());
 $.ajax({
              type: 'POST',
              contentType: 'application/json; charset=utf-16',             
              dataType: 'json',
              url: "www.xyx.com/formpost.aspx/SaveCustomerEmail",
              success: function (msg) {
                  alert('done');
              },
              error: function (msg) { 
                alert(JSON.stringify(msg)) }
          });

No correct solution

OTHER TIPS

You need to set a CORS policy on the receiving domain (www.xyx.com)

header("Access-Control-Allow-Origin: *");

To allow requests from any domain.

For a more involved look at CORS see: http://fritsvancampen.wordpress.com/2013/02/03/cross-site-origin-requests-aka-cross-origin-resource-sharing/

Two things:

  1. You need to use a complete url, such as 'http://www.xyx.com/formpost.aspx/SaveCustomerEmail', otherwise the browser will be looking for a resource called www.xyz.com on your server.
  2. You're going to run into the Same Origin Policy. jQyery's .ajax() function includes a JSONP data type to get around this. The server needs to allow cross-domain requests, of course.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top