jQuery Ajax:返回值给调用者? [英] jQuery Ajax: return value to caller?

查看:26
本文介绍了jQuery Ajax:返回值给调用者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 jQuery 代码.我调用了一个 Ajax 函数文件 file.php,其中包含一些字段,例如:

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

我会再次分配给 jQuery 函数吗?如果是这样,我该怎么做?我附上了一个示例文件:

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>

推荐答案

success 函数带有一个参数,该参数包含获取的数据.所以在你的例子中:

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 ...
    }
});

jQuery 文档中有更多示例.

这篇关于jQuery Ajax:返回值给调用者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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