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

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

function update_cart_detail()
    var aData = new Array();
    var jTableData = JSON.stringify(aData);
    return  jTableData;

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


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

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

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

OK, shall we wait for the OP to return?