我似乎遇到了发送一串URL的问题。 URL如下所示:
它在JS中发送所有信息,但只有当它到达php页面时才会看起来像这样:
我的Ajax设置如下:
jQuery.ajax({
type: "POST",
dataType: "html",
data: "type=add" + "&1A=" + pubName + "&1B=" + postID + "&1C=" + PostTitle + "&1D=" + timeStamp + "&1E=" + pdfLink + "&1F=" + imgLink + "&1G=" + fullArticleLink,
url: "../wp-content/plugins/visual-editor-custom-buttons/js/wpDataSend.php",
success: function(results) {
if (results.indexOf("done") >= 0) {
showNotifier(8000,'#43d32b','Title, Pub Name, Image, Date, PDF & Article link have been saved!');
} else {
showNotifier(8000,'#d32b2b','Could not save... Please try again!');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("Status: " + textStatus);
console.log("Error: " + errorThrown);
showNotifier(8000,'#d32b2b','Error: ' + textStatus + ' | ' + errorThrown);
}
});
我正在从PHP页面收集数据,如下所示:
$newtype = $_POST['type'];
$pubName = $_POST['1A'];
$postID = $_POST['1B'];
$PostTitle = $_POST['1C'];
$timeStamp = $_POST['1D'];
$pdfLink = $_POST['1E'];
$imgLink = $_POST['1F'];
$Fullarticle = $_POST['1G'];
我该如何纠正?
答案 0 :(得分:4)
答案 1 :(得分:1)
试试encodeURIComponent。这将使URL中的某些字符脱离以符合UTF-8标准。
var encodedURL = encodeURIComponent(str);
答案 2 :(得分:0)
将您的数据更改为:
data: {type: "add", 1A: "pubName"....//and so on},
你必须在价值附近加上引号。