I am trying to send a variable with PHP to jQuery where I want to use this variable to append to a specific div.
Here is how I send the variables to jQuery onclick
:
<a onclick="searchEmail('<?php echo $location ?>');">
Then I begin the jQuery function like this:
function searchEmail(location) {
This how the ajax part in the function looks like, and it works perfectly, but I want to use the location
variable for this part of the code: $(location).appendTo('#test');
so that I append the text in location
to a specific <p
with ID #test
.
function searchEmail(email,title,content,location,siteurl) {
$(document).off("click", "#confirm").on("click", "#confirm", function (event) {
var $url = (admin_ajax.url);
$.ajax({
type: "POST",
url: $url,
datatype: "html",
data: { 'action': 'search_notify_email', email: email, title: title, content: content, location: location, siteurl: siteurl },
success: function() {
searchNotification();
console.log( location );
$('<p>'+location+'</p>').appendTo('#test');
},error:function() {
searchNotificationError();
}
});
});
}
Text
')` to make sure it worked first. And then `$(''+location+'
')` and I know location contains data. But do I need to declare it some other way to be able to use it in `success` – jockebq Mar 26 '19 at 14:02