Shawn Roller
Shawn Roller

Reputation: 1121

Change Ajax Data field parameters with html input

I've created a visualization with Google Charts based on the data returned from a query run on a server. I'm using an Ajax command to send the query.

Is there a way to dynamically modify the query based on a user's html input? I'd specifically want to change the data: parameter to include a range that the user specifies.

Here is the Ajax command that I'm using:

  var json;
$.ajax({
        url: 'http://10.10.48.20:9200/kpi/mroutes_by_lane/_search',
        type: 'POST',
        data :
            JSON.stringify(
                {
                    "query" : { "match_all" : {} }
                }),
        dataType : 'json',
        async: false,
        success: function(data){
            json = data;
        }
    })

Upvotes: 0

Views: 348

Answers (1)

Kenneth
Kenneth

Reputation: 28747

Yes,

You could just fetch the data from the HTML and put it in the data like this:

 var json;
$.ajax({
        url: 'http://10.10.48.20:9200/kpi/mroutes_by_lane/_search',
        type: 'POST',
        data :
            JSON.stringify(
                {
                    "query" : { "match_all" : {}, 
                                "some_field", $("#textboxid").val() }
                }),
        dataType : 'json',
        async: false,
        success: function(data){
            json = data;
        }
    })

And in your HTML:

<input type="text" id="textboxid" />

Upvotes: 1

Related Questions