试图回到这里的基础知识,并通过Ajax发送一个JSON对象到我的PHP。我甚至无法得到那部分,因为我得到一个JSON错误。这里是jQuery代码:传递JSON对象与jQuery的ajax
jQuery(".deletebutton").on("click", function() {
var employees = [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName": "Jones" }
];
var dataString = JSON.stringify(employees);
// Lets put our stringified json into a variable for posting
var postArray = {json:dataString};
jQuery.ajax({
type: 'POST',
url: 'index.php?option=com_recordings&task=deletevideos&format=raw',
data: postArray,
dataType: 'json',
success: function(data){
if (data == "blah")
alert(data);
}
});
});
我得到这个错误(当我检查errorThrown
):语法错误:JSON.parse:意外的字符。我检查了jsonlint.com它是有效的JSON。我究竟做错了什么?
辉煌,thx。 – Tom