2017-04-17 9 views
0

この投稿要求を送信しようとしましたが、「返信」ボタンをクリックしても応答はありません。コンソールログにもエラーは報告されません。 「返信」リンクがクリックされると、テキストエリアが親コメントに追加され、ボタンが表示され、テキストエリアの下に「返信」が表示されます。codeigniterメソッドを使用したAjaxポストリクエスト

のjQuery:これがクリックされたとき、私は送られたAJAXポストリクエストをしたい

$("a#reply").one("click", function() { 
    var comCode = $(this).attr("name"); 
    var parent = $(this).parent(); 

    parent.append("<br /><textarea class='form-text' name='new-reply' id='new-reply' required='required'></textarea><input type='hidden' name='child_table' id='child_table' value='child' /><input type='hidden' name='code' id='code' value='"+comCode+"' /><input type='submit' class='form-submit' id='form-reply' name='new_reply' value='Reply' />") 

}); 

$("#form-reply").click(function(){ 
var child_table = $("#child_table").val(); 
var comment = $("#new-reply").val(); 
var code = $("#code").val(); 

$.ajax({ 
    type: "POST", 
    url: "/new_login/index.php/user_authentication/check_comments", 
    data: { 
     new_reply : 1, 
     child_table : child_table, 
     new_replies : comment, 
     code: code 
    }, 
    success: function(data){ 
     alert('Success!'); 
    } 
    }); 
}); 

PHP:あなたはAJAX呼び出しのためのコントローラのコードをエコーする必要があり

public function check_comments() 
    { 
    // New Reply 
    if(isset($_POST['new_reply'])) 
    { 
     $new_reply_table = $_POST['child_table']; 
     $new_reply_name = $this->session->userdata['logged_in']['username']; 
     $new_reply_text = $_POST['new_replies']; 
     $new_reply_date = date('Y-m-d H:i:s'); 
     $new_reply_code = $_POST['code']; 

     if(isset($new_reply_text)) 
     { 
     $data = array(
      'user' => $new_reply_name, 
      'text' => $new_reply_text, 
      'date' => $new_reply_date, 
      'par_code' => $new_reply_code 
     ); 
     $this->user_authentication_model->check_comments($new_reply_table, $data); 
     } 
     $data['email'] = $this->user_authentication_model->show_user_email(); 
     $data['get_comments'] = $this->get_comments(); 
     $data['get_total'] = $this->user_authentication_model->get_total(); 
     $this->load->view('user_page', $data); 
    } 
    }   

       ... 
+0

あなたの関数 'check_comments' code –

+0

あなたの返事ありがとうございます。私は方法を掲載しました。 –

+0

あなたのAJAXをデバッグしてください。あなたの要求と応答を確認してください。クロムを使用している場合は、[ネットワーク]タブでヘッダーを含むすべてのリクエストと応答を見つけることができます。また、私は通常、ajaxリクエストをデバッグするためにクロムアプリケーションを使用します。 「郵便配達員」は、これらの状況で非常に便利です。 –

答えて

0

public function check_comments() 
{ 
// New Reply 
if(isset($_POST['new_reply'])) 
{ 
    $new_reply_table = $_POST['child_table']; 
    $new_reply_name = $this->session->userdata['logged_in']['username']; 
    $new_reply_text = $_POST['new_replies']; 
    $new_reply_date = date('Y-m-d H:i:s'); 
    $new_reply_code = $_POST['code']; 

    if(isset($new_reply_text)) 
    { 
    $data = array(
     'user' => $new_reply_name, 
     'text' => $new_reply_text, 
     'date' => $new_reply_date, 
     'par_code' => $new_reply_code 
    ); 
    $this->user_authentication_model->check_comments($new_reply_table, $data); 
    } 
    $data['email'] = $this->user_authentication_model->show_user_email(); 
    $data['get_comments'] = $this->get_comments(); 
    $data['get_total'] = $this->user_authentication_model->get_total(); 
    echo json_decode($data); // dont load view 
} 

}

あなたのAjaxで

+0

ご返信ありがとうございます。残念ながら、返信ボタンをクリックしたときに推奨された変更があっても反応が得られません。ログも生成されません。 –

関連する問題