I am trying to get POST from javascript to a php webpage and am using ajax to do so. I am a noob and am therefore having difficulty with the syntax.
all within the same function,
my url is generated by:
var id = markers[i].getAttribute("id");
var name = markers[i].getAttribute("name");
var url = "markerpages.php?name=" + name + "&id=" + id;
then I use this in linking to the webpage:
<a href="'+ url +'" id="postData">link to PHP webpage</a>
then my jquery is run using that id:
$(document).ready(function() {
$('.postData').click(function() {
console.log("outside ajax is working");
console.log(url);
$.ajax({
type: "POST",
url: ' + url + ',
data: {
source1: "some text",
source2: "some text 2"},
success: function (data) {
console.log(data);
console.log(url);
console.log("inside ajax is working");
}
});
});
});
I then have my on my php page:
if (isset($_POST['source1'])) {
$src1 = $_POST['source1'];
echo $src1;
}
var_dump($_POST);
I don't fully understand the query syntax necessary here, but even when I simplified it to just the ajax and an on click, I was having difficulty posting to the proper URL, and getting an empty var_dump($_POST). I had been trying to just post to markerpages.php without any id or name attached to it.
initially I had run the ajax as a function outside of this function that was triggered by an onclick() of the link, but I was having too much difficulty passing throughthe dynamic URL, so I settled on this. I am a inexperienced, to say the least.
Sincere thanks for any and all help.