JQuery / Javascript同步调用

时间:2010-07-16 11:06:02

标签: jquery

我试图在修改后获取cookie的值并将其传递给脚本(通过http GET)。

这是我的代码:

<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>

我希望在执行editCookieValue()之前确保函数fetchCookieValue()已完成作业。

完成此任务的最佳解决方案是什么?

1 个答案:

答案 0 :(得分:0)

看看http://docs.jquery.com/AjaxQueue
它为方法调用提供了一个顺序队列。

相关问题