0

why this code give error like "Warning: json_decode() expects parameter 1 to be string, array given in <b>E:\wamp\www\datefun\show_cart_update.php</b> on line". Please help me. I am new in php and json

<html>
<head>
<title>Untitled Document</title>
<script src="js/jquery-1.9.1.min.js"></script> 
</head>

<body>
<script>
function update_cart_detail()
{
    var aData = new Array();
    aData[0]={
                "session_id":"64qu9ng2o8o996s21bjt9321h1",
                "order_id":"26",
                "design_id":"21",
                "order_pcs":2,
                "item_rate":1000,
                "item_amt":2000
              }
    aData[1]={
                "session_id":"64qu9ng2o8o996s21bjt9321h1",
                "order_id":"26",
                "design_id":"25",
                "order_pcs":1,
                "item_rate":2000,
                "item_amt":2000
              } 
    var jTableData = JSON.stringify(aData);
    return  jTableData;
}

$(document).ready(function(){
    $("#update_cart").click(function(){
        //my jsons data prepare like 
        var jSonsData=update_cart_detail();
    $.post('show_cart_update.php', jSonsData, function(data){
        alert( data );
    })
    .fail(function() {
        alert( "Posting failed." );
    });
    return false;

    });
});

</script>
<button type="submit" name="update_cart_action" value="update_qty" id="update_cart" title="Update Cart" class="button btn-update" onClick="update_cart_detail()"><span><span>Update Cart</span></span></button>
</body>
</html>

Edited by pritaeas: Removed header text.

5
Contributors
5
Replies
31
Views
2 Years
Discussion Span
Last Post by diafol
0

I think your show_cart_update.php probably is just return the array of results. What you need to do is echo json_encode($your_result_array) so that the data returned is in json format.

0

You quote a php error yet we see no php code. Why is that?

0

Post your show_cart_update.php code. So It will also help the other to find an right answer for you. If your question is related to JavaScript / DHTML / AJAX please post in that forum and you will get answer as soon..

0

Also, I think you should omit onClick="update_cart_detail()" since you trigger function and whole AJAX process by clicking id="update_cart" which is that button.

0

OK, shall we wait for the OP to return?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.