js跨域提交表单

版权所有,禁止匿名转载;禁止商业使用。

下面是前台js代码部分

$.ajax({

  url: "
http://tttcuxiao.uz.taobao.com",<span
 style="white-space:pre"> </span>//这里是提交url例子链接

  type: "get",<span style="white-space:pre"> </span>//jsonp必须是get方式,post不支持,注意

  dataType: "jsonp",

  data: $("#inquiryform").serialize(),

    jsonp: "callback",

  jsonpCallback: "flightHandler",//可以自定义修改,懒的人可以直接?就可以了

  beforeSend: function () {

      $("#inquirypost").val("loading...");

  },

  success: function (msg) {

      if(msg.txt=="success"){ //msg.txt对应下面后台代码

      $("#inquirypost").val("Sended");         

          alert("Your inquiry Submitted Successfully");

      }

      else{

      $("#inquirypost").val("Failed");

      alert(msg.txt);

      }

  }, 

  error: function (XMLHttpRequest, textStatus, errorThrown) {

      $("#inquirypost").val("error");

      alert("net error,please again!");

  }

            });

下面是url页面后台的代码部分

string msg = "flightHandler({\"txt\": \"success\"})";//这里flightHandler对应上面的自定义回调名称,txt对应msg.txt

Response.Write(msg);

Response.End();

是不是很简单就实现了呢

 

0 0