How to fix the jquery with ajax code localhost says object object error
How to fix the jquery with ajax code localhost says object object error
When i call this jquery function with ajax getting this error
[object Object]
$('a#room_no').click(function()
var roomNumber = $(this).text();
alert(roomNumber);
var href = $(".room_check_out_form").attr('href');
$.ajax(
type: "POST",
url: href,
data:
roomNumber: roomNumber
,
dataType: "JSON",
success: function(data)
console.log(data);
alert(data.roomNumber)
,
error: function(err)
alert(err);
);
);
Use
console.log(...) instead of alert(...) and let us know what you see instead. I'd imagine you're getting an error and falling to alert(err), however alert() reveals no details about an object, whereas console.log() will.– Tyler Roper
Sep 15 '18 at 20:30
console.log(...)
alert(...)
alert(err)
alert()
console.log()
1 Answer
1
In your error handler, err is an object; the alert(err) is causing '[object Object]' to be shown in an alert dialog.
error
err
Changing your error handler to something like this should log more useful information to the console. Inspect the properties of the err object:
err
error: function(err)
console.log(err);
console.log(err.responseText);
alert(err.responseText);
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy
$('a#room_no').click(function() var roomNumber = $(this).text(); alert(roomNumber); var href = $(".room_check_out_form").attr('href'); $.ajax( type: "POST", url: href, data: roomNumber:roomNumber, dataType: "JSON", success: function(data) console.log(data); alert(data.roomNumber) , error: function(err) alert(err); ); );
– Manivel D
Sep 15 '18 at 20:26