开发者

JQuery / Javascript synchronous calls

开发者 https://www.devze.com 2023-01-07 19:56 出处:网络
I\'m trying to get the value of the cookie after it\'s been modified and pass it to a script (via http GET).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消