jQuery .post gets null data
This is my first post here, so I hope I'm doing it appropriately.
I have several jQuery $.post
calls that work just fine. They send data to a PHP script that modifies a database and returns some data. No problem.
But this one doesn't work. The returned data is just NULL.
$.post("act_addTaskLog.php",
{description: $("#logFormDescription").val(), complete: $("#logFormComplete").is(':checked'), taskId: $("#logFormTaskId").val(), user: <?php echo $_SESSION['user']; ?>},
function(data) {
alert("data: " + data);
}
);
开发者_如何学Python
I've tried everything I can think of, to no avail. I've even tried just one line in my PHP script:
die("true");
Firebug shows that the script is being executed, but it's not completing. The alert message displays just with the label "data:" in it, no actual data.
Thanks in advance for your help!
I feel like an idiot now. The problem was outside the code I posted here.
The $.post call is being made as the button action on a Dialog. I added a keydown listener for the Dialog (in the "open" method), so it would submit when Enter is pressed.
For some reason, pressing Enter reloaded the entire page. So I added this line to my keydown listener code:
window.stop();
That line was causing my problems with the callback data. Removing it fixed this issue. My actual $.post code was just fine.
精彩评论