how can i pass query string parameter in payload with jason data using javascript ajax post call

Viewed 54

Every time a user searches, I have to send a request. So I'm utilizing kendo multi-select and implementing it using an ajax post call.

var payload ={
  "vFilters": [
    {
      "field": "DistLocationIds",
      "values": [
        "2787"
      ]
    },
    {
      "field": "VdistLocationIds",
      "values": []
    },
    {
      "field": "createdByLocationLevelId",
      "values": []
    },
    {
      "field": "taskLevelId",
      "values": [
        "118"
      ]
    }
  ],
  "rangeFilters": [
    {
      "greaterThanOrEqual": "2022-06-11",
      "field": "startDate"
    },
    {
      "lessThanOrEqual": "2022-07-11",
      "field": "endDate"
    }
  ],
  "sorts": [],
  "limit": 50,
  "q": "s"
};


var new1 = new kendo.data.DataSource({
  transport: {
                    read: function(options) {
                        $.ajax({
                             delay: 350, // wait 250 milliseconds before triggering the request
                             url: "https://tasklist",
                             type: "post",
                             data: JSON.stringify(payload),
                             dataType: 'json',
                             contentType: "application/json"
                        });
                    },
                    
                    contentType: "application/json",
                    beforeSend: function(req) {
           req.setRequestHeader('Authorization', "Bearer @Session.AuthToken~");
       },
        processResults: function (data) {   
                //console.log("results: "+data.results.length);
                var res = [];
                if(data && data.results){
                    for(var i  = 0 ; i < data.results.length; i++) {
                        res.push({id: data.results[i].objectId, text: data.results[i].title});
                    }
                }
                return {
                    results: res
                }
            },
            complete: function(){
            }
                }
});
$("#islTasks").kendoMultiSelect({
        placeholder: "Select Tasks...",
        filter: "contains",
        autoBind: false,
    dataValueField: "objectId",
    dataTextField : "title",
    dataSource : new1
});

I've tried several techniques, but none of them have worked. Anyone have any ideas on how to pass json data in an array plus a query string parameter in a payload request using a post ajax call?

Now I have to pass the query string parameter in the variable I made which is payload data. Could someone kindly help me with this?

0 Answers
Related