dimanche 28 juin 2015

jquery is this a valid http request

I have this http request

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.

what i did is removing the newlines and put the whole text in .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('httpURL',
       { parameter1: "parameter value", parameter2: "parameter value" })

i wonder if i should pass my json request as a parameter

in case of the whole picture** i am working on sense elasticsearch plugin

Aucun commentaire:

Enregistrer un commentaire