Quick question about the data returned by a jquery.ajax () call (EDITED)
EDIT: The original problem was caused by a silly syntax error somewhere else where I fixed it. I have a new problem though as described below
I have the following jquery.ajax call:
$.ajax({
type: 'GET',
url: servicesUrl + "/" + ID + "/tasks",
dataType: "xml",
success : createTaskListTable
});
The function is createTaskListTable
defined as
function createTaskListTable(taskListXml) {
$(taskListXml).find("Task").each(function(){
alert("Found task")
}); // each task
}
The problem is that it doesn't work, I get an taskListXml
undefined error . The jQuery documentation states that success functions are passed on three arguments, the first being data.
How do I pass the data returned .ajax()
to my function with a variable name of its own choice.
My problem is I am getting XML from a previous ajax call! How is this even possible? This previous function is defined as function convertServiceXmlDataToTable(xml)
, so they don't use the same variable name.
Completely confused. Is this a caching problem? If so, how can I clear the browser cache to get rid of the earlier XML?
Thanks!
a source to share
See my comment. If you are using IE, GET AJAX requests are cached. jQuery can solve this for you by adding a random querystring variable to the query. Just change your AJAX call to this:
$.ajax({
type: 'GET',
url: servicesUrl + "/" + ID + "/tasks",
cache: false,
dataType: "xml",
success : createTaskListTable
});
This will automatically add a random sequence of requests, which will prevent the browser from caching the request.
a source to share
Try to define your callback in line like this:
success: function createTaskListTable(data, textStatus, xhr) {
console.dir(data, textStatus, xhr);
}
If the data is indeed returned as null, you can get an idea of āāthe other fields, especially xhr.
Note that error callbacks are invoked with (xhr, textStatus, errorThrown).
a source to share