javascript - jQuery multiple data decoding on server side -


scenario:

i have jquery.ajax call submitting 3 arrays server saving database. need decode combined data object being transferred server 3 arrays.

the server runs in php

if scenario ambiguous, asking, how split $input 3 arrays again. (this on php side.)

expected results:

breaking object 3 seperate arrays processing.

current results:

internal server error when start process first array.

note before code: still learning, please tips/pointer welcomed.

code:

jquery.ajax

jquery.ajax({     url: "save_all.php",     type: "post",     datatype: 'json',     data: { grades: json.stringify($scope.grades), commutators: json.stringify($scope.commutators), sgrades: json.stringify($scope.sgrades)},     success: function (data) {         console.log(data);     },     error: function (data) {         console.log(data);     } }); 

save_all.php

    <?php          $input = json_decode(file_get_contents("php://input"), true);          $grades = $input["grades"];         $commutators = $input["commutators"];         $sgrades = $input["sgrades"]; 

you don't have json entire post data, have url encoded key/value pairs, of values json, don't need access raw post data. each of json strings in standard $_post array.

php:

$grades = json_decode($_post['grades']); $commutators = json_decode($_post['commutators']); $sgrades = json_decode($_post['sgrades']); 

note: datatype: 'json' in ajax request refers response data type, not request.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -