2014-03-03 54 views
0

我想从其他网站启用表单发布。假设我在我的网站中有一个表单,并且希望为其他网站启用该表单发布。从其他网站发布表单(跨域和跨网页服务器)

我有asp.net网页www.xyx.com \ formpost.aspx 与字段EMail.and我想启用我的页面表单post.for所有谁发布数据到我的网站。 like

1)www.test.com \ emailpost.php表单从这个网站发布。

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从本网站发表邮件。

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)) } 
      }); 

回答

0

两件事情:

  1. 你需要使用一个完整的URL,如'http://www.xyx.com/formpost.aspx/SaveCustomerEmail',否则浏览器会寻找一个资源称为www.xyz.com在你的服务器上。
  2. 您将碰到Same Origin PolicyjQyery's .ajax() function包含一个JSONP数据类型以解决此问题。当然,服务器需要允许跨域请求。