JQuery Ajax: return value for caller?

I have jQuery code. I called the Ajax function file, file.php, which has several fields, for example:

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

Will I assign a jQuery function again? If so, how do I do this? I have 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>
+3
source share
2 answers

The function successtakes a parameter that contains the extracted 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 ...
    }
});

Additional examples are provided in the jQuery documentation .

+12
source
jQuery.ajax({
     type:"POST",
     url:"file.php",
     data:"id1="+val1+"&id2="+val2,
     success:function(data){
       jQuery("#div_id").html(data);
    }
-one
source

All Articles