I have a simple script that gets the value of a textarea and posts this via AJAX. If I post “??” I get strange values. If I log out the value it retrieves before posting it all is correct. But the POST data my script receives includes the jQuery version number. My code and results are are below. Should I be escaping this somehow ?
var value = $("#textarea").val();
$.ajax({
url:'index.php',
type:'POST',
data:'text='+value,
dataType:'JSON',
success:function(data){}
});
My post data comes through as “jQuery17106460378167700797_1345234676316” for the value of text.
It’s a POST request, not GET, and should be:
PHP
Also, setting the dataType to JSON evaluates the response as JSON and returns a JavaScript object. The JSON data is parsed in a strict manner, any malformed JSON is rejected and a parse error is thrown. This means any malformed JSON, and your ajax call will fail.