JQuery / Javascript synchronous calls
I'm trying to get the value of the cookie after it's been modified and pass it to a script (via http GET).
Here's my code:
<script>
function editCookieValue() {
// function that sets/edits cookie C开发者_运维技巧
}
</script>
<script type="text/javascript">
function fetchCookieValue() {
// returns value of cookie C
}
jQuery.ajax({
dataType: 'jsonp',
type: 'GET',
jsonpCallback: 'test',
url: 'http://example.com/cgi/send?cookie='+fetchCookieValue(),
success: function(data, status, request) {
}
});
</script>
I want to make sure the function editCookieValue()
has finished the job first before executing fetchCookieValue()
.
What's the best solution to accomplish this task?
Take a look at http://docs.jquery.com/AjaxQueue
It provides a sequential queue for method calls.
精彩评论