Reputation: 1
I've being trying to get jquery's $.post() function to work, but I can't seem to get it right even without sending any data. I can see in the sending page's network tab that the request is sent with a 200 (OK) response, but the network tab on the receiving page is not registering any posts. The code for the post request is stored in a js file linked to the sender page:
//clicking a button with the id 'submitscore' triggers the request
$('#submitscore').click(
function() {
event.preventDefault();
$.post("recordscore.php");
});
The receiving page is loading fine when accessed, and it doesn't even have any php code in it at the moment, just html. What I'm trying to get to work seems like such a simple thing, what am I doing wrong?
Upvotes: 0
Views: 104
Reputation: 186
Your post request will must contain the form data or any data you want to send so give the paragraph you want to send id and get it's content on the page and simple post the request like this and get the data inside you php file from $_POST['paragraph'].
<div id="paragraph"></div>
$('#submitscore').click(
function() {
event.preventDefault();
var paragraph = $("#paragraph").html();
$.post("recordscore.php", {paragraph:paragraph} ,function(data){
alert(data);
});
});
Upvotes: 1