views:

157

answers:

2

I am trying to use this piece of code to serialize a form AND send an extra variable not found in the form, at the same time. The following line of code is what I expected, but sadly does not work.

var thePage = theFilename();
$.post("pagedetail.php", { $("#PageDetailForm").serialize(), thePage: thePage },
    function(data) {
        alert(data); 
});

Any ideas?

+1  A: 

Try this for the second parameter to $.post:

 { form: $("#PageDetailForm").serialize(), thePage: thePage }
karim79
Sadly, this splits up the data into two arrays. One with Form, with one sting in it, and another with thePage. Nearly there though :)
Andy Barlow
+2  A: 
    var serialized = $('#PageDetailForm').serialize();
    serialized.thePage = thePage;

    $.post("pagedetail.php", serialized,
    function(data) {
        alert(data); 
});
Kemo
This doesn't seem to add thePage onto the end of the form values. My Print_R in PHP only shows that the form fields have been submitted :(.Close though... Any other thoughts???
Andy Barlow
Oh... I found this to work:var serialized = $('#PageDetailForm').serialize() + "Thanks for your help though!!!
Andy Barlow
then try adding an <input type="hidden" value="thePageValue" />, it'll be serialized with the rest. @Andy Barlow
Kemo