English 中文(简体)
如何从 JavaScript 调用 JQuery 函数( 在非同步调用后)
原标题:How to call JQuery function from JavaScript (after asynchronous call)
最佳回答

目前,您的 jQuery 代码在文档已准备就绪的处理器中, 所以( 显然) 它会在文档准备好后立即运行 - 与您的 Ajax 调用完全无关的时间。 相反, 将您的 jQuery 代码放在自己的函数中, 在设置 < code> abj 后立即调用它。 或者直接移动 jQuery 代码到您设置 < code> abj 的函数中 :

  var json_data = http_request.responseText; 
  obj = eval("(" + json_data + ")");
  //at this point I have the information I want in "obj"
  // either process obj directly here, or call a function to do it...
  processData(obj);

  ...

  function processData(obj) {
     // your jQuery code here, using obj
  }

不过,既然你正在使用jQuery, 最好还是用 http://appi.jquery.com/cortion/ajax/"rel="nofollow" 来做Ajax, jjax 函数 。 我建议使用 http://api.jquery.com/jQuery.getJson/"rel="nofolp"\\\\\code>$.getJson() 。

$.getJSON("yourURLhere", function(obj) {
    // your jQuery code using obj here
});
问题回答

当您使用 jQuery s AJAX 调用时,您可以在收到数据后提供执行函数。它甚至有一个自动解析 JSON 的变量,例如:

$.getJSON(url, options, function(response) {
    ... do something with the data ...
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签