Ajax post method not working
ajax, html, javascript, jquery, post
Solution
What do the variables name and text contain? Rather than doing
var name = document.getElementById('name').innerHTML;
var text = document.getElementById('text').innerHTML;
You can do:
var name = $("#name").val();
var text = $("#text").val();
You may need to pass the datatype object too:
$.ajax({
type: "POST",
url: "php/post.php",
data: { postName: name, postText: text},
dataType: "json",
success: function() {
$('#paragraph').html("worked");
}
});
Problem
I am currently creating a website and am having trouble using AJAX to post my data. I have a button and when clicked the following code is processed... ``` var name = document.getElementById('name').innerHTML; var text = document.getElementById('text').innerHTML; $.ajax({ type: "POST", url: "php/post.php", data: { postName: name, postText: text}, success: function() { $('#paragraph').html("worked"); } }); ``` This definitely opens the post.php page but it is not passing through the desired data. Am I doing something wrong? Thanks in advance