简体   繁体   English

Ajax调用中没有帖子数据

[英]No post data in ajax call

im having problems with an ajax request. 我有一个ajax请求的问题。 the function is to increment/decrement items in a shopping cart. 功能是增加/减少购物车中的商品。 When the increment event is fire the post array comes up empty when printed. 触发增量事件时,打印后的数组将变为空。

Firebug shows the params being sent in the post request but in the controller nothing arrives. Firebug在发布请求中显示了正在发送的参数,但是在控制器中什么也没有到达。

The solution implemented is a bit scruffy but this is the way it has to be. 所实施的解决方案有些麻烦,但这是必须的方法。 The jquery is a non anonymous method outside the document.ready signature which could well be a contributor to the issue. jQuery是document.ready签名之外的非匿名方法,很可能是导致该问题的原因。

here's what I have... 这就是我所拥有的...

jQuery jQuery的

    function increment_item($ciid){     
    $("#processing").fadeIn("fast");
    $.ajax({
        url: "<?=BASE_URL?>landing/inc_cart_item",
        type: "post",
        dataType: "json",
        data: {id:$ciid,},
        success: function(data){
            $("#processing").fadeOut("fast");
            if(data.error) {
                alert(data.error);
            } else {
               // parent.$('#line1').text(data.line1);
                //parent.$('#line2').text(data.line2);
                //parent.$('#address-dialog').dialog('close');
                alert(data.line1);
            }
        }
    });
    //return false;           
};

The trigger in the view... 视图中的触发器...

<a href="#" onClick="increment_item(<?=$item['cart_item_id']?>)" class="qty-inc-button" >More</a>

The controller method... 控制器方法...

    function inc_cart_item(){

    $return_val = $this->cart_model->increment_cart_item($this->session->userdata('cart_id'),$this->input->post('id'));

}

EDITED TO ADD GENERATED SOURCE... 编辑以添加通用源...

The table data 表数据

            </thead>
                    <tbody id="item_2823">
            <tr>
                <td>
                    <img src="http://localhost/cdn/images/112/7/thumb_lemberger2010.jpg">
                                                <p style="color: #666;">Bader</p>
                                            <p style="font-size: 16px;">Stettener Lindhälder Lemberger</p>
                    <a href="#" onclick="remove_item(2823)" id="remove-item-button" class="remove-item-button">Remove this item</a>
                </td>
                <td class="align-td-center">
                    8.20€                    </td>
                <td class="align-td-center">
                    <a href="#" onclick="increment_item(2823)" id="qty-inc-button" class="qty-inc-button">More</a>
                        1                        <a href="#" onclick="decrement_item(2823)" id="qty-dec-button" class="qty-dec-button">Less</a>
                    <input id="item_id" class="item_id" value="2823" type="hidden">
                </td>
                <td class="align-td-center">
                    <span id="value-shipping-2823">8.20€</span>
                </td>
            </tr>
        </tbody>
                                <tbody id="item_2824">
            <tr>
                <td>
                    <img src="http://localhost/***/cdn/images/112/5/thumb_kerfttropfle2010.jpg">
                                                <p style="color: #666;">Bader</p>
                                            <p style="font-size: 16px;">Kerftströpfle</p>
                    <a href="#" onclick="remove_item(2824)" id="remove-item-button" class="remove-item-button">Remove this item</a>
                </td>
                <td class="align-td-center">
                    5.10€                    </td>
                <td class="align-td-center">
                    <a href="#" onclick="increment_item(2824)" id="qty-inc-button" class="qty-inc-button">More</a>
                        1                        <a href="#" onclick="decrement_item(2824)" id="qty-dec-button" class="qty-dec-button">Less</a>
                    <input id="item_id" class="item_id" value="2824" type="hidden">
                </td>
                <td class="align-td-center">
                    <span id="value-shipping-2824">5.10€</span>
                </td>
            </tr>
        </tbody>

Generated jquery 生成的jQuery

function increment_item($ciid){     
    $("#processing").fadeIn("fast");
    $.ajax({
        url: "http://localhost/***/***/landing/inc_cart_item",
        type: "POST",
        dataType: "json",
        data: {id:$ciid},
        success: function(data){
            $("#processing").fadeOut("fast");
            if(data.error) {
                alert(data.error);
            } else {
               // parent.$('#line1').text(data.line1);
                //parent.$('#line2').text(data.line2);
                //parent.$('#address-dialog').dialog('close');
                alert(data.line1);
            }
        }
    });           
};

Again the jQuery function im trying to use here is outside all the other generated jQuery in the $(document).ready(function() { code block, i dont know if this could be the cause. 我再次尝试在此处使用的jQuery函数在$(document).ready(function(){代码块中的所有其他生成的jQuery之外,我不知道这是否可能是原因。

I've been wrestling with it a little while now, all help is appreciated. 我已经努力了一段时间,感谢所有帮助。

Thanks 谢谢

Are you sure the data is being posted correctly? 您确定数据发布正确吗? You have a comma inside your data json. 您的数据json中有一个逗号。

Also you could try: 您也可以尝试:

   data: JSON.stringify({id:$ciid})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM