I need to serialize all inputs from a form into a JSON string.
With the help of this post, I can successfully create a valid string as below:
{\"input01\
After scouring Google and the jQuery site, i've come to the personal conclusion that the $.load function will convert any variable passed to it as a querystring (As my original problem above outlined).
If you wish to pass a JSON string through it, it has to be manually typed.
To get around this, I used the low level $.ajax function instead.
An advantage of using this method meant I could also send POST data using the standard .serialize() function rather than having to convert my form data into JSON.
My final code:
var formData = $('#form').serialize();
$.ajax({
type: "POST",
url: "ajax.php",
data: 'Query01=01&Query02=02',
dataType: 'json',
success: function(data){
if (data==1){
$.ajax({
type: "POST",
url: "ajax.php",
data: formData,
success: function(html){
$("#wrap").replaceWith(html);
}
});
}
}
});
If anyone else has a solution, please comment.