带Ajax的Codeigniter:成功功能不起作用 [英] Codeigniter with ajax: success function not working

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

问题描述

我的javascript文件$ .ajax函数
中的成功函数存在问题:

I have a problem with success function in my $.ajax function in javascript file:

$("#country select").change(function () { 
            var country_value = $(this).val(); 
            $.ajax({
                url:base_url + "Search_controller/testing_controller", 
                method: 'post',
                data: {country_val: country_value },
                dataType: 'json',
                success: function(data){
                    console.log('done : ' + data);  
                },
                   error: function (reponse) {
                console.log('Problem with ajax');
                }

            });

我的Controller函数

   <?php 

class Search_controller extends CI_Controller{

    public function index(){

    }


    public function testing_controller(){
        $data ="statessssssss";
        echo json_encode($data);
    }

  }
?>

**


问题是代码什么都不做,我不知道问题是什么
总是在浏览器日志 Ajax问题中返回我

The Problem is the codes do nothing, i don't know what the problem Always return to me in Browser log 'Problem with ajax'

**

推荐答案


我发现解决方案是由于CSRF的安全性



$("#country select").change(function () { 
             var country_value= $(this).val(); 
             var data = { /* params  */
                    "country": country_value,
                     "state": '001'
                };
              data[csfr_token_name] = $.cookie(csfr_cookie_name);
            $.ajax({
                url:base_url + "Search_controller/testing_controller", 
                method: 'post',
                data: data,
                dataType: 'json',
                success: function(data){
                    console.log('done : ' + data);  
                },
                   error: function (reponse) {
                console.log('Problem with ajax');
                }

            });




此代码有效

This Code Working

这篇关于带Ajax的Codeigniter:成功功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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