propaganja
propaganja

Reputation: 123

SQL error or PHP error it returning in my ajax [object object]

The ajax is being called when the button inside the modal window is click. So I got a button then it pop up a modal window with the yes or no button and if click yes it will trigger this ajax and send data to my php. it actually save or update my table in my database but it returns an [object object] in my ajax when it returns.

here is the php

// get data
$selGuest = $_POST["selGuest"];

include("openDB.php");

//3.) insert a record

$insertintoCanceled = "insert into tbl_canceled "
        ."(reserved_id, guest_id, checkin, checkout, type_id, numAdults, numChildren, transacstatus, amountDue)"
        ."("
        ."SELECT * FROM tbl_bookings where reserved_id = " .$selGuest
        .")";
if(!mysql_query($insertintoCanceled, $con))//if it fails
    {
    echo json_encode(array('msg'=>'Error')) //error msg goes here
    die('Error: ' . mysql_error() . "\n");//show the mysql error

    }
echo json_encode(array('msg'=>'Successfully updated')) //success msg goes here



include("closeDB.php");
?>

and here is my ajax

var canceldata_json = {
            'selGuest': selGuest,
    };
    $.ajax({
            type: "POST",
            data: canceldata_json,
            dataType:'json',
            url: "./php/cancelBooking.php",
            success: function(msg) {
                    alert("guest information updated real")
                    $('#confirmDialog').fadeOut('slow');

            },
            error:function(msg){
            alert(msg)
            }
    });

Upvotes: 0

Views: 616

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191779

It's parsing the JSON you return. Do this instead:

alert(msg.msg);

Upvotes: 2

Related Questions