简体   繁体   English

jQuery这是一个有效的http请求

[英]jquery is this a valid http request

I have this http request 我有这个http请求

GET /deals/couchbaseDocument/_search
{
    "query" : {
        "match" : {
            "amenities" : "Maids "
        }
    }
}

when i put it in curl , it gives me results, i want to build a web app to call that request. 当我将它放在curl中时 ,它给了我结果,我想构建一个Web应用程序来调用该请求。

what i did is removing the newlines and put the whole text in .getjson() 我所做的是删除换行符并将整个文本放在.getjson()中

as this: 这样:

var query = $("#query").val();
        query = query.replace(/(\r\n|\n|\r)/gm,"");
        $.getJSON(query, function (results) {
            alert("success");
            alert(results);
        })
        .success(function () { alert(" second success"); })
        .error(function () {
            alert("error");
            alert(query);
        });

i kept getting the error alert, i wonder if what i did is actually what should it be done to send that request 我一直收到错误警报,我想知道我实际上是否应该执行发送该请求的操作

I read this 我读了这个

I found that .getJson could be like this: 我发现.getJson可能是这样的:

$.getJSON('httpURL',
       { parameter1: "parameter value", parameter2: "parameter value" })

i wonder if i should pass my json request as a parameter 我想知道我是否应该将我的json请求作为参数传递

in case of the whole picture** i am working on sense elasticsearch plugin 如果是整个图片,**我正在研究Sense Elasticsearch插件

According to the documentation of jQuery's getJson, you can pass a javascript object ( jQuery.getJSON() | jQuery API Documentation ) so you can do something like this 根据jQuery的getJson的文档,您可以传递一个javascript对象( jQuery.getJSON()| jQuery API Documentation ),以便可以执行类似的操作

var queryData = {
    "query" : {
        "match" : {
            "amenities" : "Maids "
        }
    }
};
$.getJSON('httpURL', queryData)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM