簡體   English   中英

按鈕點擊事件后禁用頁面刷新

[英]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;
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM