Making a href link call upon a php script and run it
How do i make a href link call upon a 开发者_StackOverflow中文版PHP script without making the page refresh? Just in general? If someone could point me in the right direction it would be great. :)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js">
<script>
function trigger() {
$.ajax({
type: 'POST',
url: myfile.php,
data: data,
success: success
dataType: dataType
});
}
</script>
<body>
<a href="#" onClick="javascript:trigger();">some link</a>
</body>
For more examples and references go to http://api.jquery.com/category/ajax/ and http://api.jquery.com/jQuery.post/
Embed jQuery and use one of the AJAX commands:
- If you want to load data, use
$.load()
- If you want to send a GET/POST request use
$.get()
or$.post()
or the generic$.ajax()
method.
jQuery is your friend! http://www.jquery.com
Specifically, what you're looking for is called AJAX, and it's going to be a fun journey for you. Good luck!
Reference: http://api.jquery.com/category/ajax/
精彩评论