stijn0713 Posted June 28, 2013 Share Posted June 28, 2013 (edited) i want to post a json literal with jquery ajax method. The $_POST array on the server side is empty, thought i see with firebug that the json literal has been send. If i switch to GET method, i do receive the literal but it's not clean formatted. client-side $.ajax({ type: "GET", url: 'ajax/saveInfoAuthenticatedUser.php', data: pic_data, dataType: 'json', success: function (data) { alert(data); } }); server-side $data = $_POST['pic_data']; print_r($_POST); What is the problem? I've read alot of posts on stackexchange where people had the same problem, but nowhere i could find the reason why the post variable is empty. Extra question: What is the clean way to send a json format? should i use stringify(), json_encode or something? Edited June 28, 2013 by stijn0713 Quote Link to comment https://forums.phpfreaks.com/topic/279668-post-json-with-ajax/ Share on other sites More sharing options...
denno020 Posted June 29, 2013 Share Posted June 29, 2013 (edited) I think you need to specify both the name of the variable client side, and what it will appear as server side. So where you have this in your ajax function: data: pic_data change it to: data: {pic_data: pic_data} Oh, and also make sure that you set the type back to POST. And when returning information from the server, I always use json_encode(). Denno Edited June 29, 2013 by denno020 Quote Link to comment https://forums.phpfreaks.com/topic/279668-post-json-with-ajax/#findComment-1438440 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.