订购评估在JavaScript code使用Ajax? [英] Order of evaluation in JavaScript code using Ajax?

查看:112
本文介绍了订购评估在JavaScript code使用Ajax?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来(我)像JavaScript语句不经常运行此起彼伏。我知道他们这样做的方式,但有时它看起来像一个秀()FUNC化火,同时与隐藏()这样的逻辑失败。有回调函数的使用,像jQuery.load(some.html,thenrunthis)..

It seems (to me) like javascript statements do not always run one after another. I know they do that way but sometimes it seems like a show() func tion fires at the same time with hide() so the logic fails. There are callback functions to use, like jQuery.load("some.html",thenrunthis) ..

我需要了解的工作逻辑。任何帮助/线索?

I need to understand the working logic. any help/leads?

THX预先

推荐答案

您真的在问的是A的 AJAX 。它代表着异步的,它可以让你做不阻止的请求。回调函数,如果/请求成功的时候被执行,但你的code中的其余部分将继续执行。其中一个主要的优点这种方法是用户界面的响应。同步调用将基本上冻结浏览器,直到你的要求回报率,这可能需要一段时间。

You are really asking about the "A" in AJAX. It stands for asynchronous, and it allows you to make a request without blocking. The callback function will be executed if/when the request succeeds, but the rest of your code will continue to execute. One of the main advantages to this approach is UI responsiveness. A synchronous call will essentially freeze the browser until your request returns, which could take a while.

编辑::要扩大一点上我原来的答复,我认为我会指出,回调函数不限于AJAX请求。既然你似乎是使用jQuery,你可能想看看 jQuery的事件API 使用回调更多的例子

To expand a little on my original answer, I thought I'd point out that callback functions are not limited to AJAX requests. Since you seem to be using jQuery, you might want to look at the jQuery Events API for more examples using callbacks.

示例:假设你想回应以某种方式在一个文本输入框获得焦点。这里有一个例子直接从 jQuery的文档其中一个回调函数来回应一个输入元素获得焦点:

Example: Suppose you want to respond a certain way when a text input field gets focus. Here is an example straight from the jQuery documentation in which a callback function is used to respond to an input element obtains focus:

$("input").focus(function () {
     $(this).next("span").css('display','inline').fadeOut(1000);
});

这功能实在是一个回调函数。当用户选择了输入元素在页面上就会被调用。还有就是上面的code行动工作示范这里

That function is really a callback function. It will be called when the user selects an input element on the page. There is a working demonstration of the above code in action here.

这篇关于订购评估在JavaScript code使用Ajax?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆