到达CI控制器后,AJAX post值变为boolean [英] AJAX post values becomes boolean after reaching the CI controller

查看:52
本文介绍了到达CI控制器后,AJAX post值变为boolean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在谷歌搜索几天但仍无法解决这个问题。我有这个ajax函数,它更新mysql数据库中的记录。当我使用ajax插入新记录时,一切都很顺利,但当我通过ajax更新此记录时,它给了我403 Forbidden响应。当我使用var_dump检查从ajax传递的值时,所有值都变为boolean。下面是我的代码,希望你能帮帮我。



AJAX

<前lang =Javascript> $。ajax({
url:' updateDeal'
async: false
类型:' post'
数据:{
dealId:dealId,
dealName:dealName,
dealLocation:dealLocation,
dealCategory:dealCategory,
dealDescription:description,
dealValidDate: dealValidDate,
dealRegularPrice,
dealPromoPrice:dealPromoPrice,
dealHighlights:tourHighlight,
dealInclusion:inclusions,
dealItenerary:行程,
dealAdditionalServices:附加,
isPromo:isPromo,
isPublish:isPublish
},
beforeSend: function (){
$(' .image-loader')。show();
},
成功:功能(结果){
var obj = $ .parseJSON(results);
if (!obj.hasError){
$(' 图像加载器)隐藏();
window location = ' success?id = 2';
}
}
});





控制器



公共函数updateDeal(){

$ data = array(
Id => $ this-> input-> post(' dealId'),
< span class =code-string> dealName => $ this-> input-> post(' dealName'),
dealLocation => $ this-> input-> post(' dealLocation'),
dealCategory => $ this-> input-&g t; post(' dealCategory'),
dealDescription => $ this-> input-> post(' dealDescription'),
dealValidDate => $ this-> input-> post(' dealValidDate'),
dealRegularPrice => $ this-> input-> post(' dealRegularPrice'),
dealPromoPrice => $ this-> input-> post(' dealPromoPrice'),
dealHighlights => $ this-> input-> post(' dealHighlights'),
dealInclusion => $ this-> input-> post(' dealInclusion'),
dealItenerary => $ this-> input-> post(' dealItenerary'),
dealAdditionalServices => $ this-> input-> post(' dealAdditionalServices'),
isPromo => $ this-> input-> post(' isPromo'),
isPublished => $ this-> input-> post(' isPublish'
);
var_dump($ data);

}





结果



< pre lang =text> array(14){
[Id] =>
bool(false)
[dealName] =>
bool(false)
[dealLocation] =>
bool(false)
[dealCategory] =>
bool(false)
[dealDescription] =>
bool(false)
[dealValidDate] =>
bool(false)
[dealRegularPrice] =>
bool(false)
[dealPromoPrice] =>
bool(false)
[dealHighlights] =>
bool(false)
[dealInclusion] =>
bool(false)
[dealItenerary] =>
bool(false)
[dealAdditionalServices] =>
bool(false)
[isPromo] =>
bool(false)
[isPublished] =>
bool(false)
}

解决方案

.ajax({
url:' updateDeal'
async: false
类型:' post'
data:{
dealId:dealId,
dealName:dealName,
dealLocation:dealLocation,
dealCategory:dealCategory,
dealDescription:description,
dealValidDate:dealValidDate,
dealRegularPrice: dealRegularPrice,
dealPromoPrice:dealPromoPrice,
dealHighlights:tourHighlight,
dealInclusion:inclusions,
dealItenerary:itinerary,
dealAdditionalServices:additional,
isPromo:isPromo,
isPublish:isPublish
},
beforeSend: function (){


' .image-loader')。show();
},
成功:功能(结果){
var obj =


.parseJSON(results);
if (!obj.hasError){


I been searching in google for days but still got no answer to solve this. I have this ajax function which update a record in mysql database. When I use ajax to insert a new record, everything is smooth but when I update this record thru ajax it gives me 403 Forbidden response. When I use var_dump to check the values pass from ajax all values became boolean. Below is my code, hope you can help me.

AJAX

$.ajax({
    url:'updateDeal',
    async:false,
    type:'post',
    data:{
        dealId:dealId,
        dealName:dealName,
        dealLocation:dealLocation,
        dealCategory:dealCategory,
        dealDescription:description,
        dealValidDate:dealValidDate,
        dealRegularPrice:dealRegularPrice,
        dealPromoPrice:dealPromoPrice,
        dealHighlights:tourHighlight,
        dealInclusion:inclusions,
        dealItenerary:itinerary,
        dealAdditionalServices:additional,
        isPromo:isPromo,
        isPublish:isPublish
    },
    beforeSend: function(){
        $('.image-loader').show();
    },
    success:function(results){
        var obj = $.parseJSON(results);
        if(!obj.hasError){
            $('.image-loader').hide();
            window.location = 'success?id=2';
        }
    }
});



Controller

public function updateDeal(){

        $data = array(
            "Id"                    => $this->input->post('dealId'),
            "dealName"              => $this->input->post('dealName'),
            "dealLocation"          => $this->input->post('dealLocation'),
            "dealCategory"          => $this->input->post('dealCategory'),
            "dealDescription"       => $this->input->post('dealDescription'),
            "dealValidDate"         => $this->input->post('dealValidDate'),
            "dealRegularPrice"      => $this->input->post('dealRegularPrice'),
            "dealPromoPrice"        => $this->input->post('dealPromoPrice'),
            "dealHighlights"        => $this->input->post('dealHighlights'),
            "dealInclusion"         => $this->input->post('dealInclusion'),
            "dealItenerary"         => $this->input->post('dealItenerary'),
            "dealAdditionalServices" => $this->input->post('dealAdditionalServices'),
            "isPromo"               => $this->input->post('isPromo'),
            "isPublished"           => $this->input->post('isPublish')
        );
        var_dump($data);

    }



RESULT

array(14) {
  ["Id"]=>
  bool(false)
  ["dealName"]=>
  bool(false)
  ["dealLocation"]=>
  bool(false)
  ["dealCategory"]=>
  bool(false)
  ["dealDescription"]=>
  bool(false)
  ["dealValidDate"]=>
  bool(false)
  ["dealRegularPrice"]=>
  bool(false)
  ["dealPromoPrice"]=>
  bool(false)
  ["dealHighlights"]=>
  bool(false)
  ["dealInclusion"]=>
  bool(false)
  ["dealItenerary"]=>
  bool(false)
  ["dealAdditionalServices"]=>
  bool(false)
  ["isPromo"]=>
  bool(false)
  ["isPublished"]=>
  bool(false)
}

解决方案

.ajax({ url:'updateDeal', async:false, type:'post', data:{ dealId:dealId, dealName:dealName, dealLocation:dealLocation, dealCategory:dealCategory, dealDescription:description, dealValidDate:dealValidDate, dealRegularPrice:dealRegularPrice, dealPromoPrice:dealPromoPrice, dealHighlights:tourHighlight, dealInclusion:inclusions, dealItenerary:itinerary, dealAdditionalServices:additional, isPromo:isPromo, isPublish:isPublish }, beforeSend: function(){


('.image-loader').show(); }, success:function(results){ var obj =


.parseJSON(results); if(!obj.hasError){


这篇关于到达CI控制器后,AJAX post值变为boolean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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