I am basic ajax and using display result(form and custom value(like Json)) ajax. My code:
var obj = {"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]};
var data = $("#userForm").serialize() + "&jsonval=" + obj;
$.ajax({
datatype : "json",
type: 'POST',
url: 'all.php',
data: data,
})
My Result:
Array
(
[firstname] => frtr
[lastname] => dfgfdg
[email] => [email protected]
[num] => 2323232323
[num1] => 34334
[num2] => 2342
[num3] => 2432
[submit] => Submit
[jsonval] => [object Object]
)
Jsonval -display result [object Object].plz help with display result all employees(first name and Last name). Thanks for your feature help and correct my fault.
Because you are trying to post JSON Object in post string, so you will need to change Object into string
Change
var data = $("#userForm").serialize() + "&jsonval=" + obj;
to
var data = $("#userForm").serialize() + "&jsonval=" + JSON.stringify(obj);
Now you will get JSON content into string on server, so decode jsonval field value on server side
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With