Refreshing ajax data source with dynamic parameters

I'm binding a data source using ajax with the following code:

let ajax = new ej.base.Ajax(
url: $('#Grid').attr('data-url'),
type: "POST",
data: JSON.stringify(getParameters())
});
ajax.send();
ajax.onSuccess = function (data) {
grid.dataSource = JSON.parse(data);
};

The getParameters() function returns an object with values that the user can set dynamically.

I'm attempting to reload the data and refresh the grid by calling ajax.send() whenever the values change.

The problem is that since the ej.base.Ajax object was created at runtime, it is not posting with the new values, and the request is made with the values as they were on page load.

How can I post with dynamic values and refresh the grid with the new data that is received from the server?

Thanks


2 Replies

VI Victor November 23, 2021 06:53 PM UTC

I solved this by modifying the ajax data property before calling the send method:

ajax.data = JSON.stringify(getParameters());

ajax.send();

Are there any performance issues that could arise from using this method?

Is this memory efficient?



PS Pavithra Subramaniyam Syncfusion Team November 24, 2021 02:59 PM UTC

Hi Victor, 

It is great to hear you have solved the issue. 

You can rest the Ajax data is you stated in the last update, and it won’t create any performance/memory issue. If you are facing any issue in EJ2 Ajax library, please get back to us. 

Regards, 
Pavithra S 


Loader.
Up arrow icon