Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Ajax不断出错_Php_Jquery_Ajax_Codeigniter - Fatal编程技术网

Php Ajax不断出错

Php Ajax不断出错,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,这是我的ajax代码,我使用Codeigniter框架,我正在尝试向控制器发送数据 <script> $('#mssgg').submit(function(){ var ms = $('#mess').val(); $.ajax({ type:'POST', url:'http://localhost/index.php/C_Main_page/store_chat',

这是我的ajax代码,我使用Codeigniter框架,我正在尝试向控制器发送数据

<script>
    $('#mssgg').submit(function(){
        var ms = $('#mess').val();
        $.ajax({
            type:'POST',
            url:'http://localhost/index.php/C_Main_page/store_chat',
            data:'messege'+ms,
            error:function(data){
                alert("error");
            },
            success:function(data){
                alert("success");
            }
        }); 
    }); 
</script>

$('#mssgg')。提交(函数(){
var ms=$('#mess').val();
$.ajax({
类型:'POST',
网址:'http://localhost/index.php/C_Main_page/store_chat',
数据:'messege'+ms,
错误:函数(数据){
警报(“错误”);
},
成功:功能(数据){
警惕(“成功”);
}
}); 
}); 
我不断出错,我做错了什么

  • 您需要停止表单提交,因为它会刷新页面,从而结束ajax
  • 虽然要传递的数据字符串不正确,但应该传递对象。
    数据:'messege'+ms,

  • 这:
    data:'messege'+ms,
    应该是
    data:'messege='+ms,
    或者更好的对象
    data:{messege:ms},


    
    $('mssgg')。提交(功能(e){
    
    e、 preventDefault();//您遇到了什么错误使用url:'检查您的url..如果正确
    <script>
        $('#mssgg').submit(function(e){
            e.preventDefault(); // <----stop the form submission.
            var ms = {messege : $('#mess').val() }; //<----create an object
            $.ajax({
                type:'POST',
                url:'http://localhost/index.php/C_Main_page/store_chat',
                data:ms, //<----and pass that object here.
                error:function(data){
                    alert("error");
                },
                success:function(data){
                    alert("success");
                }
            }); 
        }); 
    </script>