Answer the question
In order to leave comments, you need to log in
Why does a button click reload the page?
Good evening ladies and gentlemen. There is a site on Jumbla and I fasten my module with jQery\AJAX to it. I need that after the user enters data and clicks on the button, php code is executed in the background and eventually tells the user the result without refreshing the page. This is all I did. But what's the problem.
<form>
<button onclick="Pusk(document.getElementById('user'),document.getElementById('tel'),document.getElementById('sms'),document.getElementById('to'),document.getElementById('ajax'))">Отправить</button>
</form>
function Pusk(_user,_tel,_sms,_to,_ajax)
{
var user = encodeURIComponent(_user.value);
var tel = encodeURIComponent(_tel.value);
var sms = encodeURIComponent(_sms.value);
var to = encodeURIComponent(_to.value);
ajax = _ajax;
var query = 'user='+user+'&tel='+tel+'&sms='+sms+'&to='+to;
Request(query);
}
function Request(query)
{
req.open('post', '/php/1.php' , true);
req.onreadystatechange = Refresh;
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
req.send(query);
}
function Refresh()
{
var a = req.readyState;
if( a == 4 && req.status==200)
{
var b = req.responseText;
ajax.defaultValue = b;
alert(b);
return(false);
}
else
{
ajax.defaultValue = "Отправка";
}
}
<button type="button" onclick="Pusk(document.getElementById('user'),document.getElementById('tel'),document.getElementById('sms'),document.getElementById('to'),document.getElementById('ajax'))" return false;">Отправить</button>
Answer the question
In order to leave comments, you need to log in
And who will provide the code for your Start function? Well, I'm guessing at random that you don't return false at the end of the function.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question