我的jquery帖子出了什么问题?

时间:2015-11-13 10:18:42

标签: jquery ajax forms form-submit

$("#login").click(function() {
   var mydata = $("#loginform").serialize();

   $.post("http://events.rate-mate.com:5000/auth", {
     data: mydata
   }, function(response) {
     $("#result").html(response);

   }, "json");
});

它不发送任何参数,也没有响应。

1 个答案:

答案 0 :(得分:0)

请参阅以下示例,了解通过ajax post

提交表单



//callback handler for form submit
$("#loginform").submit(function(e) {
  var postData = $(this).serializeArray();
  var formURL = $(this).attr("action");
  $.ajax({
    url: formURL,
    type: "POST",
    data: postData,
    success: function(data, textStatus, jqXHR) {
      //data: return data from server
    },
    error: function(jqXHR, textStatus, errorThrown) {
      //if fails      
    }
  });
  e.preventDefault(); //STOP default action
  e.unbind(); //unbind. to stop multiple form submit.
});

$("#loginform").submit(); //Submit  the FORM

<form name="loginform" id="loginform" action="sample_url.php" method="POST">
  First Name:
  <input type="text" name="fname" value="" />
  <br/>Last Name:
  <input type="text" name="lname" value="" />
  <br/>Email :
  <input type="text" name="email" value="" />
  <br/>
</form>
&#13;
&#13;
&#13;