Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax: return value to caller?

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>
like image 291
venkatachalam Avatar asked Oct 18 '25 16:10

venkatachalam


1 Answers

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.

like image 111
Athena Avatar answered Oct 21 '25 05:10

Athena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!