0

I am trying to pass the user's checked HTML radio button value to a PHP variable using Jquery/Javascript and Ajax.

The following is a simplified version of the HTML/Javascript:

    $("input[name=bus_plan]").on('change', function(){
            var $postID = "=" + $('input:radio[name=bus_plan]:checked').val();
        $.ajax ({
            type: "GET",
            url: "product-group.php",
            data: {"postID" : $postID },
            success : function(data){
                        alert("done");
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert("problem: " + errorThrown);
            } 
        });
    });

The ajax call shows a success (i.e. there is a "done" alert.)

This is the product-group.php:

    <?php
            echo "hello world<br>";
            $postid = $_GET['postID']; 
            echo "The postID is ".$postid;
    ?> 

Any help in understanding/fixing the fact that product-group.php does not appear to run would be most appreciated.

Thank you.

1
  • 1
    Check the script by calling it's real URL (in the browser, not via AJAX), plus check using firebug or similar that the ajax call is done. Also, looks like you're not using the output of your script in javascript. Commented Feb 6, 2013 at 10:53

3 Answers 3

1

Try alert(data) instead of alert("done") to see if jQuery is receiving the correct response.

Sign up to request clarification or add additional context in comments.

Comments

0

Your echo output is in "data" var, its like the "return" for ajaxcalls.

Tru alert(data) or append the data content on some div.

Comments

0

Try rewriting your ajax call like this-

$("input[name=bus_plan]").on('change', function(){
            var postID  = $('input:radio[name=bus_plan]:checked').val();
        $.ajax ({
            type: "GET",
            url: "product-group.php?postID="+postID,
            success : function(data){
                        alert("done");
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert("problem: " + errorThrown);
            } 
        });
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.