In your javascript file you can use the post
method or you can use ajax
like in the example below to send your data:
$.ajax({
type : 'post',
url : 'currentphpfile.php',
//Here is where the data is put
data : {
"ajax" : "1",
"otherData" : "abc"
},
success : function(data, textStatus, jqXHR) {
//Do something with the data here like insert it into the document
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
//Do something to fix the error
},
dataType : 'text' //Or automatically parse a json response with 'json'
});
For this to work, you would need something in your php file that could handle the request like this:
if (!empty($_POST['ajax']) && $_POST['ajax']==1){
//Do stuff with the other post data
//Here's how to return the data to your script:
//If you chose a text response above:
echo $importantData;
exit;
//If you chose json
echo json_encode(array("title" => $title, "text" => $text /*, etc... */));
}
I haven't tested this code for bugs, but you probably get the idea.