I'm getting a "canceled" status whenever I do a jquery $.post(). It seems like an asynchronous problem? I access the local project with http://127.0.0.1:8933/myproject/default/index.html
index.html:
<script>
$(document).ready(function() {
$('#mybutton').click(function() {
var post_url = get_url(); // resolves to "/myproject/default/process_func"
var data = ...;
do_action(post_url, data);
});
});
</script>
<a href="" id="mybutton"> Click me! </a>
util.js:
function doPost(url, data) {
$.post(url, data).then(doSuccess, doFail):
function doSuccess(data) {
alert('Successful!');
}
function doFail(data) {
alert('Failed!');
}
}
function do_action(url, data) {
var jsondata = JSON.stringify(data);
// some other stuffs...
doPost(url, jsondata);
}
The idea is to post some data back to the server for processing using json data. A user will click on the anchor button, the do_action()
will fire, and then it'll be posted in doPost()
.
This seems to work since my I'm seeing the json data passed to my processing function on the server. However, I'd see the alert message "Failed!" pop up every time even though the data has been processed. In chromium's debug panel, I see under "Network" tab that the post has a status of "(canceled)" and the entire line would be highlighted in red. The Type stated is "Pending".
I think this is an asynchronous problem, but I'm unsure how to fix it.