How can I create an object in jquery

339
November 22, 2016, at 2:24 PM

I have created an object in jquery

var obj= {'First': 'yellow','Second': 'red'};

I want to post this object to a vb function which has an objcolor which has primary and tint as properties. The function has two other parameters; sport and car. my post is

$.post('URL.action('ColorReal'),{'sport': 'bowling', 'car': 'olds', 'objcolor': 'obj'});

I set a breakpoints after the function in vb.net controller to see if parameters of function are populated sport as bowling and car has old but the objcolor has nothing. I have tried JSON.stringify(objcolor) in the post and still nothing is passed. How should the object setting in the post be constructed?

Answer 1

try like

var ob = { 
  'sport': 'bowling', 
  'car': 'olds', 
  'objcolor': [{ 
    'First': 'yellow', 
    'Second': 'red' 
  }] 
} 
 
$.post('URL.action("ColorReal")', ob);

Rent Charter Buses Company
READ ALSO
“View More” button after every three bottom scroll using jquery

“View More” button after every three bottom scroll using jquery

I have tried a lot but can't add show more button automatically just after every three scroll down. .

359
Passing variable through ajax on multiple pages

Passing variable through ajax on multiple pages

I am passing variable to add_user. php ,now I want to pass same variable to another page countuser.

311
Dynamically create html elements in view based on the returned jason object mvc5

Dynamically create html elements in view based on the returned jason object mvc5

Im developing a mvc5 application using codefirst approach. Im returning a jason object to a view in this way,.

211
Appending li to ul using appendChild

Appending li to ul using appendChild

hi i have a images and i want to create a nav li for each image item. .

325