JSON array is empty


i am doing a password reset form using Jquery and PHP

if i try to submit an email id it should sent and email and report back the response text as success so that the user knows email has been sent.

But i am stuck with JSON submit as i have an empty array to decode at the serverside.
I am using minified version of json2.js from the official json.org website

Here is the code.

	var formdata = $("#log-box").serializeArray();
	formdata = JSON.stringify(formdata);
	var notifymsg;
			type: "POST",
			url: "forgot-pass.php",
			contentType: 'application/json',
			data: formdata,
			success: function(responsedata){
				var some = responsedata.split("&");
				$.each(some, function(index,value){
				error: function(o, s, e){
						alert("Form not posted \

formdata alerted gives:


PHP forgot-pass.php


gives me


Can someone point out what i might be doing wrong? i am a designer and this is the first time i am trying to do JSON :stuck_out_tongue:

What happens if you comment out your second line that turns the array into a string which may be whats sending an empty $_POST array.

i think the stringifier function will encode the string to the correct JSON format and that is what i used it for. i have seen threads that encoding and decoding in the correct JSON format is tricky and i saw it here the easier way is to do this

I tried using the code from http://www.factsandpeople.com/facts-mainmenu-5/26-html-and-javascript/89-jquery-ajax-json-and-php

but it seems like the content type passed string/array/object is not recognized properly at the server side.

thanks for the quick response, im still trying to figure out what type of content it should be. I prefer it to be array rather than string because its the best method to submit and process a form :slight_smile:

Usually with arrays you don’t need to set a content-type yourself as jQuery usually does this for you.