Sending A POST or GET request to php script using javascript
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?
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
}
});
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.
Now would be as good a time as any to learn jQuery
精彩评论