Banshi Gurjar
Banshi Gurjar

Reputation: 44

AJAX:How to pass a single parameter either by serialize the form or send a single parameter

I have a form for a single field on my page, I just want to know either it is better to send a single parameter like

var myObject = {myParameter:'My Value'};

OR

var myObject = {myParameter : myForm.Serialize()};

Upvotes: 0

Views: 218

Answers (1)

Darren
Darren

Reputation: 70718

It depends on what the service/controller is expecting to receive. If the parameter is a form use .serialize() else just specify the value directly.

Behind the scenes .serialize() creates a text based string based upon the form elements. I.e.:

formItem=FormItem1&FormItem2=formItem2

So it really makes no difference.

Upvotes: 2

Related Questions