How can I modify the "GET" request generated by ajax.load()?
How can I modify the "GET" request generated by ajax.load()?
I'm implementing a web-based file manager, with the directory tree displayed in a div on the left and file information displayed in a DataTable in a div on the right. I plan to initiate a .load() to update the file table when a user clicks on a directory in the left div.
I'd like to pass the path associated with the directory to the server along with the request for data by doing something like ajax.url("/getDirInfo?[path]"); but haven't implemented it yet. I specify "/getDirInfo" as the ajax source in my DataTable script, and noticed that the browser sends the following string to the server to request JSON data - http://192.168.1.7/getFiles?_=1537371591555. The number in the parameter changes with each refresh.
Where does this string of numbers come from, how are they intended to be used, and is there a way to replace them with the desired path? Or will I have to pass the path separately and ignore the "_=1537371591555" parameter?
This question has an accepted answers - jump to answer
Answers
Has do do with disabling cache for the ajax request:
http://api.jquery.com/jquery.ajax/
Look for the
cache
option for more details. If desired you can change the request type to POST to eliminate the _=1537371591555 from being appended to the URL.Kevin
Thanks for the reply. Looks like it's possible to add the path parameter using ajax: {url: '192.169.1.7/getFiles', data: '/test/test2'}.
The server receives the following URL in the GET request:
http://192.168.1.7/getFiles?0=%2F&1=t&2=e&3=s&4=t&5=%2F&6=t&7=e&8=s&9=t&10=2&_=1537478247801.
The string after "0=" contains:
/ t e s t / t e s t 2
I found a better solution for dynamically passing a parameter to the program generating JSON data.
var param = p_node.path; // the parameter I want to pass
if (param != null) {
var tab = $('#myDataTableName').dataTable();
tab.api().ajax.url('/getFiles?'+param).load();
}
If param = '/HTMfiles', for example, the server receives:
GET /getFiles?/HTMfiles&_=1537724298346 HTTP/1.1