Codeigniter 中的 JQuery Ajax POST [英] JQuery Ajax POST in Codeigniter

查看:32
本文介绍了Codeigniter 中的 JQuery Ajax POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 POST 方法搜索了很多教程,也在这里看到了已回答的问题,但我的 POST 仍然不起作用...我想如果你们看到我没有看到的东西,我应该把它贴在这里!

I have searched a lot of tutorials with POST methods and saw answered questions here too but my POST still doesn't work...I thought i should post it here if you guys see something that i don't!

我的 js - messages.js:

$(document).ready(function(){   

    $("#send").click(function()
    {       
     $.ajax({
         type: "POST",
         url: base_url + "chat/post_action", 
         data: {textbox: $("#textbox").val()},
         dataType: "text",  
         cache:false,
         success: 
              function(data){
                alert(data);  //as a debugging message.
              }

     return false;
 });
 });

我的观点 - chat.php:

<?php $this->load->js(base_url().'themes/chat/js/messages.js');?> //i use mainframe framework which loading script this way is valid



<form method="post">
    <input id="textbox" type="text" name="textbox">
    <input id="send" type="submit" name="send" value="Send">
</form>

最后一个我的控制器 - chat.php

//more functions here

function post_action()
{   
    if($_POST['textbox'] == "")
    {
        $message = "You can't send empty text";
    }
    else
    {
        $message = $_POST['textbox'];
    }
    echo $message;
}

推荐答案

$(document).ready(function(){   

    $("#send").click(function()
    {       
     $.ajax({
         type: "POST",
         url: base_url + "chat/post_action", 
         data: {textbox: $("#textbox").val()},
         dataType: "text",  
         cache:false,
         success: 
              function(data){
                alert(data);  //as a debugging message.
              }
          });// you have missed this bracket
     return false;
 });
 });

这篇关于Codeigniter 中的 JQuery Ajax POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆