2016-03-31 9 views
0

現在、ユーザーが正常に完了した後、別のHTMLファイル(つまり、dashboard.html)にリダイレクトしたいと考えています。私はこれを解決するためにヘッダーを使用することができます知っているが、私は私のコードにどこに追加する必要がありますか分からない。PHPを使用して別のhtmlファイルにリダイレクト

if (mysqli_query($Link, $Query)) { 
     $lastID = mysqli_insert_id($Link); 
     $Query2 = "INSERT INTO $table_2 VALUES (NULL, 
     '".$lastID."')"; 
     if (mysqli_query($Link, $Query2)) { 
      $message = "You've sucessfully created the account!"; 
      echo json_encode(array('success'=>'true', 'action'=>'login','html'=>$message, 'console.log'=>$Query)); 
     } 
     else { 
      $message = "Error occur in query2"; 
      echo json_encode(array('action'=>'error','html'=>$message, 'console.log'=>$Query)); 
     } 
    } 
    else { 
     $message = "Error in query1"; 
     echo json_encode(array('action'=>'error','html'=>$message, 'console.log'=>$Query)); 
    } 

お元気にお手伝いします。

あなたがPHPで構築されたコードに <a>タグを追加することができますいずれか

答えて

0
if (mysqli_query($Link, $Query)) { 
     $lastID = mysqli_insert_id($Link); 
     $Query2 = "INSERT INTO $table_2 VALUES (NULL, 
     '".$lastID."')"; 
     if (mysqli_query($Link, $Query2)) { 
      $message = "You've sucessfully created the account!"; 
      echo json_encode(array('success'=>'true', 'action'=>'login','html'=>$message, 'console.log'=>$Query)); 
     } 
     else { 
      $message = "Error occur in query2"; 
      echo json_encode(array('action'=>'error','html'=>$message, 'console.log'=>$Query)); 
     } 
    } 
    else { 
     $message = "Error in query1"; 
     echo json_encode(array('action'=>'error','html'=>$message, 'console.log'=>$Query)); 
    } 

jQueryの

$.ajax({ 
    type: 'POST', 
    dataType: 'json', 
    data: postData, 
    url: 'n3228691.scm.tees.ac.uk/Yii/MACC/models/…';, 
    success: function(data) { 
     console.log(data); 
     if(data.action === "login"){ 
      window.location="dashboard.html"; //succeed insert 
     }else{ 
      alert('There was an error handling your registration!'); 
     } 
    }, 
    error: function(data) { 
     alert('There was an error handling your registration!'); 
    } 
}); 
+0

Yup私はAjaxを使用しています –

+0

@JasonLauあなたはそのサンプルを投稿できますか?その後、ajaxで成功した後にリダイレクトを行う必要があります。 – Chay22

+0

$アヤックス({ \t \t \t \tタイプ: 'POST'、 \t \t \t \tデータ型: "JSON"、 \t \t \t \tデータ:POSTDATA、\t \t \t \t \t \t URL:「httpsを:/ /n3228691.scm.tees.ac.uk/Yii/MACC/models/class.model.registerUser.php?action=register '、 \t \t \t \t \t \t \t \t成功:関数(データ){ \t \t \t \t \tコンソール。ログ(データ); \t \t \t \t \t $( '

').html(data.html).appendTo( '。msg'); \t \t \t \t \t //$.mobile.loading('hide '); \t \t \t \t \t window.location = "https://n3228691.scm.tees.ac.uk/Yii/MACC/gallery1.html"; \t \t \t \t}、 \t \t \t \t \t \t \t \tエラー:機能(データ){ \t \t \t \t \tアラートが( 'あなたの登録を処理中にエラーが発生しました!'); \t \t \t } \t \t \t}); –

0

<a href="new_page.php">Click this link for new page</a> 

それとも、あなたがトラップし、ユーザーのクリックをするJavaScript/jQueryのを使用して、新しいページにリダイレクトすることができます

<div id="redir">Click this link</div> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script> 
    $(function(){ 
     $('#redir').click(function(){ 
      window.location.href = 'new_page.php' 
     }); 
    }); 
</script> 

あるいは、ヘッダがすでに送信されているとjoakkinenの答えに指定されたPHP header()メソッドが動作しない場合、あなたはこのHTMLをエコーすることができます

echo '<meta HTTP-EQUIV="REFRESH" content="0; url=new_page.php">'; 

(含有量が0リダイレクトする前に、秒の遅延の数を表す)

+0

if(mysqli_query($ Link、$ Query2)){ $ message = "アカウントを正常に作成しました! == $ query);};}}};}}};}}}};}}}}}};}}}};}}}}}}};}}};}}};}}};}}}}; header( '場所:dashboard.htmll'); } –

+0

わかりました。あなたが取引の途中だったことを理解できませんでした。その場合、joakkinenは 'header()'メソッドが他のヘッダが送信されていない場合にのみ動作するという点を除いて答えがあります。もしそれらがあれば、次のようにHTMLをページにエコーすることができます: 'echo '';' *( 'content = 0'リダイレクトするまでの秒数を表します)* – gibberish

0

Iを追加することができ...

header('Location: dashboard.html'); 
exit; 
+0

これを試して、ファイアバグでテストしました。しかし、HTMLコードをそこに表示することはできますが、表示することはできません –

関連する問題