Reputation: 10542
I seem to be having problems with sending over a string of a URL. The URL looks like this:
Its sending all that information inside the JS but it only looks like this once it gets to the php page:
My Ajax is set up like so:
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);
}
});
And I am gathering up the data from the PHP page like so:
$newtype = $_POST['type'];
$pubName = $_POST['1A'];
$postID = $_POST['1B'];
$PostTitle = $_POST['1C'];
$timeStamp = $_POST['1D'];
$pdfLink = $_POST['1E'];
$imgLink = $_POST['1F'];
$Fullarticle = $_POST['1G'];
How can I correct this?
Upvotes: 0
Views: 364
Reputation: 908
Change your data to this:
data: {type: "add", 1A: "pubName"....//and so on},
You have to put quotes and around the value.
Upvotes: 0
Reputation: 11148
Try encodeURIComponent. This will escape certain characters in the URL to conform with UTF-8 standards.
var encodedURL = encodeURIComponent(str);
Upvotes: 1
Reputation: 46728
You can send post params the right way using
jQuery.ajax({
...
data: {param1 : value1, param2: value2}
Upvotes: 4