Home Ask Login Register

Developers Planet

Your answer is one click away!

Rais February 2016

Array object to php using ajax

How can i send data like this to php using ajax



Rogin Thomas February 2016

stringify before sending Eg :

var postData = [
{ "id":"1", "name":"bob"},
{ "id":"2", "name":"jonas"}]

this works,

url: Url,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(postData) //stringify is important,

sudhakar February 2016

try json_encode for more refer - http://php.net/manual/en/function.json-encode.php

Ognjen Babic February 2016

Do it like so, using jQuery(which you need to include in your script):

    var data={};

    data= {

            async: true});


And on the page where you want to catch this data, do it like this:


And so on.

paranoid February 2016

Try this

$(document).on("click", "#your element", function () {
    type: 'POST',
    url: "your_url",
    data : {"title":"mr","fname":"john","lname":"Annah","oname":"Clement","staffid":"123"},,
    success: function (result) {
        ### your action after ajax

Ranjith February 2016

you can pass it in data like this,

        url: 'url',
        type: 'GET',
        data: {  title:"mr",fname:"john",lname:"Annah",oname:"Clement",staffid:"123" } ,
        contentType: 'application/json; charset=utf-8',
        success: function (response) {
            //your success code

Post Status

Asked in February 2016
Viewed 3,979 times
Voted 9
Answered 5 times


Leave an answer

Quote of the day: live life