jQuery的阿贾克斯:返回值调用者? [英] jQuery Ajax: return value to caller?
本文介绍了jQuery的阿贾克斯:返回值调用者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些jQuery code。我已经叫一个Ajax功能的文件,为file.php,有一些领域,如:
<输入类型=无线电值=嘿>牛奶< /输入取代。
我将分配到再次jQuery函数?如果是这样,我怎么办呢?我连着一个示例文件:
< HTML>
< HEAD>
< LINK REL =样式表HREF =examples.cssTITLE =当代TYPE =文本/ CSS>
<脚本SRC =jQuery的-1.2.6.js类型=文/ JavaScript的>< / SCRIPT>
<脚本SRC =jQuery的-impromptu.1.6.js类型=文/ JavaScript的>< / SCRIPT>
<脚本>
$(文件)。就绪(函数(){
$阿贾克斯({
键入:GET,
网址:为file.php,
数据:ID,
成功:函数(){
VAR TXT = ID;
$ .prompt(TXT,{不透明:0.2});
},
错误:函数(){
window.location的(错误);
}
});
});
< / SCRIPT>
<身体GT;
< /身体GT;
< / HTML>
解决方案
在成功
函数有一个参数,它包含所取得的数据。因此,在你的例子:
$(文件)。就绪(
函数(){$阿贾克斯({
键入:GET,
网址:为file.php,
数据:ID,
成功:函数(TXT){
$ .prompt(TXT,{不透明:0.2});
},
// ... 更多 ...
}
});
更多的例子是在 jQuery的文档。
I have some jQuery code. I have called an Ajax function file, file.php, that has some fields, like:
<input type="radio" value="plz">Milk</input>.
Will I assign into again jQuery function? If so, how do I do it? I attached a sample file:
<html>
<head>
<LINK REL=StyleSheet HREF="examples.css" TITLE="Contemporary" TYPE="text/css">
<script src="jquery-1.2.6.js" type="text/javascript"></script>
<script src="jquery-impromptu.1.6.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$.ajax({
type:"GET",
url:"file.php",
data:id,
success:function(){
var txt=id;
$.prompt( txt,{ opacity: 0.2 });
},
error:function(){
window.location("ERRoR");
}
});
});
</script>
<body>
</body>
</html>
解决方案
The success
function takes a parameter, which contains the fetched data. So in your example:
$(document).ready(
function(){ $.ajax({
type:"GET",
url:"file.php",
data:id,
success:function(txt){
$.prompt( txt,{ opacity: 0.2 });
},
// ... more ...
}
});
More examples are in the jQuery documentation.
这篇关于jQuery的阿贾克斯:返回值调用者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文