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

);
);






$('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






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

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ