$(function(){ $('#submit').click(function (){ var data = { q: $('#q').val() }; $.ajax({ url: 'http://api.hgotoh.work/sitteru.pl', type: 'POST', contentType: 'application/json', data: JSON.stringify(data) }).done(function(data){ $('#answer').text(data.message); }).fail(function(data){ $('#answer').text('通信障害かも…'); alert(data); }); }); });