Answer the question
In order to leave comments, you need to log in
How to send a query to the database without refreshing the page?
Hello, today I decided to move to a new level for myself and improve the quality of my site.
I became very interested in how things like checking the availability of a nickname, logging into an account without reloading the page, and similar things are done.
Having rummaged through the ezernet, I found out that the so-called AJAX technology is connected with this. I would like to know how it works, what it is, what it is, how it connects, what it is eaten with and what you can read on this issue.
Now closer to the point. I think that it is not necessary to explain in detail what exactly I want, everything is clear here. You need to authorize the user without reloading the page. I have the necessary php code, but, of course, with this approach, I will have to reload the page.
Who can advise on this? It is desirable, of course, to give an exhaustive example of how this can be done, with code, of course. I would be very grateful.
Answer the question
In order to leave comments, you need to log in
Suppose there is a form on the site that works without ajax:
In order for it to work through ajax, you need to hang a submit event handler on js, and interrupt the event in it (using the return false; method), instead of sending a request using js.
For simplicity and cross-browser compatibility, you can include jquery.
Then the following code will appear:
$(function(){ // DOM ready
$('#test_form').submit(function(){
$.post(
$(this).attr('action'), // url
$(this).serializeArray(), // data
function(answ) //callback
{
//...
},
'html' // answer type (html, text, json, ...)
);
return false;
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question