Question

I have the following code to call a ajax POST :

    $("a[href=Save]").click(function() {
        var thisform = $(this).attr("name");
        // Get all the information left in the form
        var lname = $('div[name="' + thisform + '"] input[name="lname"]').val();
        var fname = $('div[name="' + thisform + '"] input[name="fname"]').val();
        var mname = $('div[name="' + thisform + '"] input[name="mname"]').val();
        var language = $('div[name="' + thisform + '"] input[name="lang"]').val();
        var title = $('div[name="' + thisform + '"] input[name="title"]').val();
        var ptype = $('div[name="' + thisform + '"] input[name="ProfileType"]').val();
        var vip = $('div[name="' + thisform + '"] input[name="VIP"]').val();
        var vreason = $('div[name="' + thisform + '"] input[name="Vreason"]').val();

        alert (lname);

        //Set the Ajax Request
        $.post("..\ajax\profileMod.php", {
            'lname':lname,
            'fname':fname,
            'mname':mname,
            'language':language,
            'title':title,
            'ptype':ptype,
            'vip':vip,
            'vreason':vreason
        };
        .done(function(data) {
         // php code : echo json_encode(array("name"=>"Called!"));
            alert(data.name);

        });

        // Stop original behavior
        return false;
    });

I don't know where I went wrong but the code is not working. I'm trying to call a php file using the POST, and showing a message to see if the file got called correctly. All my "var" are getting to right value (I've tested all of them one by one).

I've look at so many post to find the error that my eyes hurt! So I'm asking help!!!

Thank you!

Was it helpful?

Solution

looks like you put a ";" where you should have put a ")"

        'vip':vip,
        'vreason':vreason
    }; <-- problem
    .done(function(data) {
     // php code : echo json_encode(array("name"=>"Called!"));
        alert(data.name);

Should be

        'vip':vip,
        'vreason':vreason
    }) <-- fix
    .done(function(data) {
     // php code : echo json_encode(array("name"=>"Called!"));
        alert(data.name);

i think

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top