使用Internet Explorer和jQuery Ajax错误 [英] Error with Internet Explorer and Jquery Ajax

查看:188
本文介绍了使用Internet Explorer和jQuery Ajax错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个jQuery的ajax功能:

  $。阿贾克斯({
    网址:'/ private_cloud / add_app /+ school_id +/+ APP_ID,
    数据类型:JSON,
    异步:假的,
    成功:功能(数据){
        如果(data.status == 1)
        {
            执行console.log(data.status);
        }
    },
    错误:功能(错误){
        警报(错误);
    }
});
 

在我使用的Chrome和Firefox,这是工作完美的罚款。但是,当我使用IE浏览器,它显示在控制台中1,但该数据甚至没有在数据库中插入。

这是我的code在PHP中:

 公共职能add_app($ school_id = NULL,$ APP_ID = NULL)
{
    如果($这个 - >学校 - >节省($ get_school))
    {
        回声{地位:1};
    }
    其他{
        回声{地位:0};
    }

    死;
}
 

解决方案

您还没有指定请求类型,以便它的默认,因此为GET IE浏览器是(最有可能)缓存响应。添加

 键入:POST
 

你的AJAX配置对象,如:

  $。阿贾克斯({
    网址:'/ private_cloud / add_app /+ school_id +/+ APP_ID,
    键入:POST,
    // 等等
 

I have this jquery ajax function:

$.ajax({
    url: '/private_cloud/add_app/'+school_id+'/'+app_id,
    dataType: "json",
    async: false,
    success: function(data){
        if(data.status == 1)
        {
            console.log(data.status);
        }
    },
    error: function(error){
        alert("Error");
    }
});

When I am using chrome, and firefox, this is working perfectly fine. But when I am using internet explorer, it shows in the console "1" but the data wasn't even inserted in the Database.

This is my code in PHP:

public function add_app($school_id = NULL, $app_id = NULL)
{
    if($this->School->save($get_school))
    {
        echo '{"status":"1"}';
    }
    else{
        echo '{"status":"0"}';
    }

    die;
}

解决方案

You haven't specified a request type so it's defaulting to GET therefore IE is (most probably) caching the response. Add

type: 'POST'

to your AJAX config object, eg

$.ajax({
    url: '/private_cloud/add_app/'+school_id+'/'+app_id,
    type: 'POST',
    // etc

这篇关于使用Internet Explorer和jQuery Ajax错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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