Well, lets take a moment to pause that debate and go back to the actual method, because i’ve made a misstatement.
dataType defines the RETURN type that the ajax is expecting, not the SEND type.
The data element works just fine with a fully complex Object (of any type), a String, or an Array, as defined by the jQuery specification. I will assume it does some internal conversion to format its send correctly to the server.
EDIT: Not fully complex object. PlainObject (Which… I take to mean a JSON-able object)
The problem is, then you end up with a request sent as application/json, but this as the request body: sendFormData=%7B%22wark%22%3A%7B%22imajson%22%3A%22doot%22%7D%7D
PHP doesn’t seem to know what to do with this, as in my tests it still doesn’t populate the $_POST array (probably it doesn’t parse the request body into superglobals unless it is sent with a relevant mime type).
I think you misread what I said in my previous post - I’m talking about when you send it with a mime type of application/json.
You can, of course, submit data (via Ajax, or via a standard HTML form) where one or more fields contain a JSON string. You could then access this string via the $_POST array within your PHP script, and decode the JSON string into PHP from there.
However, the most common way of sending JSON to a server is via a pure application/json request, as the OP seemed to be aiming to do.
Well it only depends on how you code your backend really. If you use the method in post #16 then PHP is just as capable of dealing with pure JSON requests as any other language
Well yes, but by that logic you can use the method in post #16 for ANY input, it’s just more complex to do so than just… sending the data like most other form data in the world.
I don’t use jQuery and I may be wrong but json is a formatted string so maybe you should change data:({title:projectTitle})
to data:(“{title:projectTitle}”)
If in your php you are receiving an empty $_POST array it indicates that your POST request succeeded but that you are sending nothing.
Have you checked for any error messages in the console?