Reputation: 51
Here is what needs to be done.
I have an html code and when use clicks into input field the javascript function is called.
The javascript function should call php file track.php which then counts the clicks.
Is it possible to run a php script from javascript?
Upvotes: 2
Views: 2982
Reputation: 5440
Try using the jQuery framework for your javascript code. And have a look at the ajax function.
$.ajax({
type: "POST",
url: "track.php",
data: form_data,
success: function(){
// code
},
error: function(){
// code
}
});
Upvotes: 7
Reputation: 400932
Yes, it is possible : you'll want to search for the "Ajax" keyword.
Ajax will allow you to send requests, from Javascript to your server, in the background -- without reloading the page.
If you just want to send a simple request, working with the XmlHttpRequest
object that's provided by the browser is quite easy.
Else, if you want more advanced stuff, you'll probably want to take a look at Javascript libraries, such as jQuery.
Upvotes: 5