javascript object to php using jquery ajax

前端 未结 1 394
一向
一向 2021-01-07 10:46

I have an array or a javascript object that I create like this: arr[arr.length]=obj where the obj is a classic JSON string like {\"id\":1}.

相关标签:
1条回答
  • 2021-01-07 11:31

    Can send the JSON and use json_decode() to turn it into a php array.

    $.post('server/path', { jsonData: JSON.stringify(arr)}, function(response){
       /* do something with response if needed*/
    });
    

    in php:

    $arr=json_decode( $_POST['jsonData'] );
    /* return first ID as test*/
    echo $arr[0]['id'];
    /* or dump whole array as response to ajax:*/
    print_r($arr);
    
    0 讨论(0)
提交回复
热议问题