在单击按钮事件后禁用页面刷新


Disable page refresh after button click event

我使用这个代码发送消息的电话。发送消息后,我收到一个带有"代码已成功发送"消息的警报。在此之后,我看到页面得到刷新,我如何在按钮单击事件后停止此页面刷新。

<?php 
ob_start();
session_start();
 $con = mysql_connect('localhost','root','');
mysql_select_db('uniquelogin',$con);
 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org        /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 <title>Password</title>
 </head>
 <body>
<br /><br />
 <table width="100%" border="0"><tr>  <td height="38" bgcolor="#FA8072" ><center><h1>
 <strong><em><font color="#F5FFFA" >LOGIN PROCESS</font></em></strong></h1></center>    
</td>
</tr></table> <br /><br />

 <?php
   $k=0;
do
 {
  $matrix_ = array();
$matrix = array();
$matrix[3][0]="h5";$matrix[3][1]="h3";$matrix[3][2]="96";$matrix[3]    [3]="45"; $matrix[3]    [4]="oo";
  $matrix[1][0]="39";$matrix[1][1]="k4";$matrix[1][2]="i2";$matrix[1][3]="j9"; $matrix[1][4]="g5";
foreach( $matrix as $val )
foreach($val as $v)
    $matrix_[] = $v;
shuffle($matrix_);
foreach( $matrix_ as $key => $val )
$matrix[ floor($key / 5) ][$key % 5] = $val;
}
while($k>0);

$key1[0]=4;
$key1[1]=2;
$key1[2]=1;
$key1[3]=5;
$key1[4]=3;
  for($i=0;$i<5;$i++)
  {
   for($j=$i+1;$j<5;$j++)
     {
       if($key1[$i]>$key1[$j])
             {
            for($y=0;$y<5;$y++)
             {
               $temp[$y]=$matrix[$y][$i];
                $temp1[$y]=$matrix[$y][$j];
              }
   for($y=0;$y<5;$y++)
      {
$matrix[$y][$j]=$temp[$y];
$matrix[$y][$i]=$temp1[$y];
}
}
}
}

$p[0]="a"; $p[1]="b"; $p[2]="c"; $p[3]="d"; $p[4]="e"; 
$p[5]="f"; $p[6]="g"; $p[7]="h"; $p[8]="i"; $p[9]="j"; 
shuffle($p);
//shuffle($a);
?>
<table  align="center" width = "45%" height="65%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><strong>&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
<td align="center"><strong><?php echo $p[0]; ?></strong></td>
<td align="center"><strong><?php echo $p[1]; ?></strong></td>
<td align="center"><strong><?php echo $p[2]; ?></strong></td>
<td align="center"><strong><?php echo $p[3]; ?></strong></td>
<td align="center"><strong><?php echo $p[4]; ?></strong></td></tr>
<tr>
<td align="center"><strong><?php echo $p[5]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[0][0]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[0][1]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[0][2]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[0][3]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[0][4]; ?></strong></td></tr>
<tr><td align="center"><strong><?php echo $p[6]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[1][0]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[1][1]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[1][2]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[1][3]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[1][4]; ?></strong></td></tr>
<tr><td align="center"><strong><?php echo $p[7]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[2][0]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[2][1]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[2][2]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[2][3]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[2][4]; ?></strong></td></tr>
<tr><td align="center"><strong><?php echo $p[8]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[3][0]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[3][1]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[3][2]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[3][3]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[3][4]; ?></strong></td></tr>
<tr><td align="center"><strong><?php echo $p[9]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[4][0]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[4][1]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[4][2]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[4][3]; ?></strong></td>
<td align="center"><strong><?php echo $matrix[4][4]; ?></strong></td></tr>
</table><br /><br />
<?php 
$k=0;
  for($g=5;$g<10;$g++)
{
$s[$k]=$p[$g];
$k++;
}
for($g=0;$g<5;$g++)
{
$code[$g]=$p[$g];
}
$k=0;
for($g=5;$g<10;$g++)
{
$code1[$k]=$p[$g];
$k++;
}
shuffle($code);
shuffle($code1);
$j=0;
for($g=0;$g<5;$g++)
{
$fcode[$j]=$code1[$g];
$j++;
$fcode[$j]=$code[$g];
$j++;
  }
for($g=0;$g<10;$g++)
{
$ky = $fcode[$g];
}
echo "<br>";
$m=0;$i=0;
 for($k=0;$k<5;$k++)
{
for($g=0;$g<5;$g++)
{
if($code1[$k]==$s[$g])
 {
 $i++;
 $val=$g;
 break;
}
 }
if($i==1)
{
$i=0;
for($g=0;$g<5;$g++)
{
if($code[$k]==$p[$g])
{
$val1=$g;
$pass[$m]=$matrix[$val][$val1];
 $m++;
break;
}
}
}
}
for  ($g=0;$g<5;$g++)
{
$valcode = $pass[$g];
}
?>
 <form action="login1.php" method="post">
 <input name="valco" type="hidden" value="<?php echo $valcode; ?>" />
 <input name="namess" type="hidden" value="<?php echo $_GET['id']; ?>" />
 <input name="pass" type="hidden" value="<?php echo $ky; ?>" />
<center><input type="submit" name="code" id="code" value="Send Code">  </center>
<br /><br />
<center>  
<font color="#FF3366"> <strong>Password :</strong></font>&nbsp;
<input type="password" name="password" id="password"  placeholder="Enter the password"     />
</center><br/><br />
 <center><input type="submit" name="submit" id="submit" value="Login" style:color="     /></center><br /><br />
</form>
</body>
 </html>
<?php
if (isset($_REQUEST['code']))
{
$_SESSION['uname'] = $_POST['namess'];
$msf=$_POST['pass'];
$valc=$_POST['valco'];
$phones = "select mobno from registration where username='".$_POST['namess']."' ";
//echo $phones;
$fr=mysql_query($phones);
$rt=mysql_fetch_object($fr);
 $phone = $rt->mobno; 
echo "<script type='text/javascript'>window.open('http://bulksmsindia.mobi    /sendurlcomma.aspx?user=20064973&pwd=crisp1996&senderid=PROJEC&mobileno=$phone&msgtext=Welcome to our Application,Please Note your code is $msf &smstype=4&priority=High')</script>";  
$upd = "UPDATE registration SET passcode='".$msf."',password = '".$valc."' where     username= '".$_POST['namess']."' ";
mysql_query($upd);
echo '<script type="text/javascript">alert("Code Sent Successfully");</script>';
echo '
//echo '<meta http-equiv="refresh" content=",login1.php">';
}
if(isset($_REQUEST['submit']))
{
$phon es = "select mobno from registration where username='".$_SESSION['uname']."' and     password = '".$_POST['password']."'  ";
//echo $phones;
$fr=mysql_query($phones);
$cout = mysql_num_rows($fr);
if($cout >= 1){
echo '<script type="text/javascript">alert("Succesfully Login");</script>';
//echo '<meta http-equiv="refresh" content=",new1.php">';
}
else{
    echo '<script type="text/javascript">alert("Invalid Login");</script>';
// echo '<meta http-equi="refresh" content=",new.1.php">';
 }

}
?>

首先回显一个显示警报视图的脚本:

echo '<script type="text/javascript">alert("Code Sent Successfully");</script>';

之后告诉浏览器页面应该立即重新加载login1.php

echo '<meta http-equiv="refresh" content=",login1.php">';

你可以把这行代码删掉。

更新:

如果您发布的代码在第二页上运行(在用户单击按钮之后),则需要寻找ajax解决方案,以便浏览器不会打开该页。您可以使用$。Ajax异步执行此请求:

$('.button').click(function(e){ // assuming your button has the class 'button'
  e.preventDefault(); // prevent browser from loading the url
  var request_url = $(this).attr('href'); // grab the url you want to call
  // perform a ajax-request
  $.ajax({
    url: request_url,
  }).success(function( response ) {
    alert('success');
  }).error(function(){
    alert('error');
  });
})

你可以在这里找到更多的信息:

使用以下

$('#yourButton').click(function(){
    // do your close action 
    return false;
})