> 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>
我建议使用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 );
});
当ajax((调用完成时,将触发Done。
如果你需要检查这个代码是否按照你的意愿完成,那么你可以有这样的东西:
$.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);});