0

In the following example am submitting a serialized form using post method. Its working fine now. But I want to pass some more extra parameter to the submitted page. How to pass that value to the form. I dont like the way to keep that value in a hidden field in that form. Is there any other way to do this?

var postUrl = 'myphppage.php';

$.post(postUrl,
    $('#myForm').serialize(),
    function(response) {    

        if(response.status){
        //do something
        }else{
        }

    },'json'
);
Alex R.
  • 4,664
  • 4
  • 30
  • 40
Arun SS
  • 1,791
  • 8
  • 29
  • 48

3 Answers3

1

Just add simply like how you do string concatenation. For eg., you wanna add a parameter, username with the value praveen, you can do this way:

$.post(postUrl,
    $('#myForm').serialize() + '&username=praveen',
    function(response) {    
        if(response.status){
            //do something
        }else{

        }
    },'json'
);

But just make sure you URLEncode the values and keys.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
0

you may try this

var postUrl = 'myphppage.php?q='+variable

and use $_GET['q'] to receive the value

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
sathish
  • 6,705
  • 3
  • 30
  • 35
0

One way you can do is:

$.post(postUrl, { form: $('#myForm').serialize(), others: 'Ramiz' }, function(response) {    
    if(response.status){
            //do something
    } else{
            //do something else
    }

  },'json'
);

You can also use hidden fields in form then you won't need anything just serialize the form object and you will have them in it:

<input type="hidden" name="others" id="others" value="Ramiz" /> <input type="hidden" name="others" id="another" value="Arun" />

Ramiz Uddin
  • 4,249
  • 4
  • 40
  • 72