构建页面以查询弹性搜索(ES)并将结果保存到文件中。我试图使用JQuery.post发送查询,我收到错误{“错误”:“请使用POST请求”}
$(document).ready(function(){
alert("ready!");
$("#go").click(function(event) {
alert("go!");
/* get some values from elements on the page: */
url=$("#host").val();
alert(url);
q=$("#q").val();
alert(q);
var posting = $.post( url, { data: q } );
/* Put the results in a div */
posting.done(function( data ) {
alert(data);
// var content = $( data ).find( '#content' );
// $( "#result" ).empty().append( content );
alert("done!");
});
});
});
答案 0 :(得分:0)
试试这个,
$.post("test.php", { name: "John", time: "2pm" })
.done(function(data) {
alert("Data Loaded: " + data);
});
并检查xhr状态,返回$ .post.also在代码中包含失败回调
.fail(function() { alert("error"); })
完整的参考文献是here