Casey Ward
Casey Ward

Reputation: 85

Ajax function on button press

I am trying to get information to post via PHP on button click, everything in my code looks right, and when I view the page source everything is filled in the way it should be. When I pull up the debugger when the button is clicked it does not make any calls at all, here is my button

<button type="button">Continue</button>

here is my ajax call

$(document).ready(function() {
    $("button").click(function(){

        var Id = <?php echo $give ?>;
        var Ids = <?php echo $rec ?>;
        var ex = <?php echo $exchange ?>;
        var ret = <?php echo $tost ?>;
        var email = <?php echo $email ?>;
        var name = <?php echo $name ?>;
        var pe = <?php echo $pe ?>;
        var re = <?php echo $re ?>;

        $.post("postts.php", { 
            Id: Id,
            Ids: Ids,
            ex: ex,
            ret: ret,
            email: email,
            name: name,
            pe: pe,
            re: re

        }, function(data){
            alert(data);
            $("p").text(data);
        }, 'json' );
    });
});

all of my vars will populate with the correct information, I just don't know why when I click the button it does nothing. I am not sure if I have made a typo, or if my syntax is wrong, this is only the second time I have done something like this.

Upvotes: 0

Views: 709

Answers (1)

meshosk
meshosk

Reputation: 86

You have error in writing variable values from PHP to JavaScript, you must wrap PHP output by quotation marks, so JavaScipt will "see" string ;)

instead of: var email = <?php echo $email ?>; write: var mail = '<?php echo $email ?>';

Upvotes: 3

Related Questions