簡體   English   中英

Ajax調用中沒有帖子數據

[英]No post data in ajax call

我有一個ajax請求的問題。 功能是增加/減少購物車中的商品。 觸發增量事件時,打印后的數組將變為空。

Firebug在發布請求中顯示了正在發送的參數,但是在控制器中什么也沒有到達。

所實施的解決方案有些麻煩,但這是必須的方法。 jQuery是document.ready簽名之外的非匿名方法,很可能是導致該問題的原因。

這就是我所擁有的...

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;           
};

視圖中的觸發器...

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

控制器方法...

    function inc_cart_item(){

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

}

編輯以添加通用源...

表數據

            </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>

生成的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);
            }
        }
    });           
};

我再次嘗試在此處使用的jQuery函數在$(document).ready(function(){代碼塊中的所有其他生成的jQuery之外,我不知道這是否可能是原因。

我已經努力了一段時間,感謝所有幫助。

謝謝

您確定數據發布正確嗎? 您的數據json中有一個逗號。

您也可以嘗試:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM