JQ 调用后台方法即Ajax方法基础知识

<link href="@Scripts/My97/skin/default/datepicker.css" rel="stylesheet" type="text/css" />
    <script src="@Scripts/My97/WdatePicker.js" type="text/javascript"></script>
    <link href="@Scripts/My97/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
   
    <!--验证引入-->
   <link href="@Css/form.css" rel="stylesheet" type="text/css" />   
    <script src="@Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="@Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="@Scripts/messages_cn.js" type="text/javascript"></script>
    <script src="@Scripts/jquery.pstrength-min.1.2.js" type="text/javascript"></script>
    <script src="@Scripts/commvalidate.js" type="text/javascript"></script>
    <script src="@Scripts/js_comm.js" type="text/javascript"></script>

    <!--验证引入结束-->
    <style type="text/css">
        .style1
        {
            width: 327px;
        }
    </style>
      <script language="javascript" type="text/javascript">
          $(function() {
              $("#btnCheck").click(function() {
                  $.ajax({
                      type: "Post",
                      url: "BuyerReg.aspx/CheckUserName",
                      //方法传参的写法一定要对,str为形参的名字,str2为第二个形参的名字 
                      data: "{'username':'" + $("#txtUserName").attr("value") + "'}",
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      success: function(data) {
                          //返回的数据用data.d获取内容 
                          alert(data.d);
                      },
                      error: function(err) {
                          alert(err);
                      }
                  });
                  //禁用按钮的提交 
                  return false;
              });
          });
   </script>

    <link href="@Css/css.css" rel="stylesheet" type="text/css" />
</head>

你可能感兴趣的:(Ajax)