3

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

<input type="radio" value="plz">Milk</input>.

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

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

2 回答 2

12

success函数接受一个参数,其中包含获取的数据。所以在你的例子中:

$(document).ready(
    function(){ $.ajax({
       type:"GET",
       url:"file.php",
       data:id,
       success:function(txt){
          $.prompt( txt,{ opacity: 0.2 });
       },
       // ... more ...
    }
});

更多示例在jQuery 文档中。

于 2008-12-23T09:04:14.590 回答
-1
jQuery.ajax({
     type:"POST",
     url:"file.php",
     data:"id1="+val1+"&id2="+val2,
     success:function(data){
       jQuery("#div_id").html(data);
    }
于 2012-07-05T22:24:05.877 回答