我想用jQuery发布数据。当我发布详细的JSON时,它可以工作。但是当我使用变量发布JSON时,它不起作用。
工作
$('#btnSave').click(function () {
let urlSave = 'http://localhost/playlist/api/playlist.php?type=playlist';
$.post(urlSave, { "name": "test", "image": "IMG/play.png", "songs": [{ "name": "Just people", "url": "src/af/AF-05-Just people.mp3" }, { "name": "Send me power", "url": "src/af/AF-09-Send me power.mp3" }] }, function (data, status) {
alert(data.success);
});
});
不起作用
$('#btnSave').click(function () {
let urlSave = 'http://localhost/playlist/api/playlist.php?type=playlist';
var d='{ "name": "test", "image": "IMG/play.png", "songs": [{ "name": "Just people", "url": "src/af/AF-05-Just people.mp3" }, { "name": "Send me power", "url": "src/af/AF-09-Send me power.mp3" }] }';
$.post(urlSave, d, function (data, status) {
alert(data.success);
});
});
我不知道我哪里错了。 我将非常感谢您的帮助。