Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling PHP scripts from Javascript without leaving current page

I'm having some trouble calling PHP scripts from Javascript without leaving the current HTML page (if it is at all possible). I understand it is possible using AJAX, although is it possible using Javascript alone?

Context:-

I want my page to perform a short animation using Javascript (using onclick), then immediately call a PHP script to insert data into a MySQL database - all without leaving the page so it does not inhibit the animation.

The animation part I can do and the inserting the data into the database, etc. but how can I call a PHP script at the end of that Javascript animation function?

Any pointers, code fragments, etc. would be greatly appreciated! ^_^

Apologies if this question has been asked previous.

like image 947
Riyan Avatar asked Mar 15 '11 01:03

Riyan


1 Answers

AJAX is Asynchronous Javascript And XML, Its a Javascript technology that allows you to send a request to the server (as your browser does when you enter a URL) and have the response in a javascript string instead of rendering it in the page.

The problem is different browsers do not implement AJAX the same way, So I suggest using jQuery for abstraction.

do this with jQuery:

<script>
$.get("backend.php",{param:value},callbackFunction);
callbackFunction(data)
{
alert(data);
}

</script>
like image 147
AbiusX Avatar answered Oct 14 '22 21:10

AbiusX