0

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)
            }
    });
2
  • what does this have to do with asp.net? odd choice of tag. Commented Sep 20, 2012 at 16:10
  • I'm sorry but I think I didn't tag it in asp.net. I tag it in php, mysql, ajax, and jquery Commented Sep 20, 2012 at 17:13

1 Answer 1

2

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

alert(msg.msg);
Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your response. it output is undefined. And before I even click ok in the alert window it already closed or fade out without doing anything.
@propaganja does closeDB.php have any output?

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.