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>

Recommended Answers

All 5 Replies

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.

Member Avatar for diafol

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

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

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.

Member Avatar for diafol

OK, shall we wait for the OP to return?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.