0
> I want recive message from post.asp how do it ?thk you..
<form name="message" action="">
<textarea type="text" id="usermsg"></textarea>
</form>
<div id="chatbox"></div>
<script type='text/javascript'>
 $(function() {
   var firstname = $("#usermsg").val();
   $("#usermsg").keypress(function (e) {

     var  firstname = $("#usermsg").val();
     if(e.which == 13) {   

        //I want to recive message from this post... how do it..**
        //$.post("post.asp",{update2:firstname} , function(data),
        $("#chatbox").append($(this).val() + "<br/>");
        $(this).val("");
        e.preventDefault();
     }
   });
 });
 </script>
4

1 回答 1

1

我建议使用ajax()

像这样的东西:

$.ajax({
  type: "POST",
  url: "post.asp",
  data: { update2: firstname } //you can add more values in here if you need
  }).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

Done 将在 ajax() 调用完成时触发。

如果您需要检查此代码是否按您的意愿完成,那么您可以使用以下内容:

$.ajax({
      type: "POST",
      url: "post.asp",
      data: { update2: firstname }, //you can add more values in here if you need
      cache: false,
      success: function(response)
      {alert(response);}                                               
       }).done(function( msg ) {
      alert( "Data Saved: " + msg );
    });

编辑:

如果您只想发布,那么您可以使用以下内容:

$.post("test.php", { name: "John", time: "2pm" }).done(function(data) {  alert("Data loaded: " + data);});
于 2013-05-14T07:27:38.277 回答