Need info on json script
In the following code what is function(payload) doing??Actually i put an alert in function(payload){} i so not see the alert
EDIT
Also i see that there is a repose from the server but why is that i do not see an alert here
$("form#form").submit(function(){
$.post(url,
{
time: timestamp,
action: "postmsg",
message: $("#msg").val()
},
function(payload) {
开发者_StackOverflowalert('1');
$("#msg").val(""); // clean out contents of input field.
},
'json'
);
Even with weird indentation I'm able to understand what's going on with my crazy JavaScript skills.
Your function(payload)
is a callback to the $.post
request. The callback will be called once the AJAX $.post
request is done.
You probably don't see it run because url
is returning a bad status code. The $.post
callback will only run if the url
is accessible with a correct status code.
For debugging try accessing url
just from your browser, and see what happens.
It will run when the HTTP response comes back from the server
… unless the browser leaves the current page first, which it will do as the you aren't stopping the normal behaviour of the submit button.
精彩评论