0

I am successfully getting data from a mysql data base until I try to drop a table. The table drops, but I cannot figure out how to keep the javascript ajax data base access from declaring an error.

How can I return ok, when there is no data to return?

The following php routine deletes a row in the order table followed by dropping the table named $tableNameInput. Inspection of the database reveals that both operations were successfully performed but the javascript ajax error processing is tripped with x.status = 0. I just need a way to tell the javascript ajax that it is really complete.

function dropCartTable($tableNameInput){/* drops the cart table and its order entry*/
    AnnLog("dropCartTable: ",$tableNameInput);
    // first drop the reference in the orders table
    $tableName = "orders";
    $query = "DELETE FROM $tableName WHERE cartDB ='$tableNameInput'";
    $result = doQuery($tableName,$query, "Could not drop orders row");
    if($result){
        // now drop this cart table
        $sql = "DROP TABLE IF EXISTS $tableNameInput";
    }
    //********do query  just does the query and logs.   it does not return if it dies.
    $result = doQuery($tableName, $sql, "Can not drop csrt table");
    if($result){

        /****** when we get to here we have successfully dropped the items. below, I tried to generate a response and it did not work.*/

        $arr = array('drop cart' => 0);
        $j = json_encode ($arr);
        echo \json_encode($j);
        AnnLog("echoed ",$j);/* this writes my logs which verify that all steps until the return are ok.*/

    }
}

thanks in advance for your help.

1
  • 1
    You are double-encoding your JSON why not just echo json_encode($arr);? Commented Apr 25, 2014 at 21:14

2 Answers 2

1
function dropCartTable($tableNameInput){/* drops the cart table and its order entry*/
AnnLog("dropCartTable: ",$tableNameInput);
// first drop the reference in the orders table
$tableName = "orders";
$query = "DELETE FROM $tableName WHERE cartDB ='$tableNameInput'";
$result = doQuery($tableName,$query, "Could not drop orders row");
if($result)
{
         // now drop this cart table
        $sql = "DROP TABLE IF EXISTS $tableNameInput";
$arr = array('drop cart' => 0);
     $j = json_encode ($arr);
    echo \json_encode($j);
AnnLog("echoed ",$j);/* this writes my logs which verify that all steps until the return are ok.*/

}
else
{
$arr = array("couldn't drop cart" => 0);
         $j = json_encode ($arr);
        echo \json_encode($j);
    AnnLog("echoed ",$j);/* .*/
}

The problem was that you was dropping the table and return result if its true and ignoring false

Sign up to request clarification or add additional context in comments.

1 Comment

Somehow some lines were deleted from above. There are actually two queries, one to the order table and the other to the cart table. In both cases I call a function called doquery which handles the query and logs to my log files. If the query fails, the log file is updated and the process dies. The if ($result is rednundant. My problem is that the json_encode does not make it back to the calling rountine. I get error number 0. Bad formatting.
0

The problem was not in the json return. It was caused by my failure to have a success callback for the ajax call.

1 Comment

How do we get this closed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.