Here is an example of my code:
Ext.Ajax.request({
url:'test.jsp',
params:{id:id,password:password},
success:function(response){
console.log(response);
var results = Ext.util.JSON.decode(response.responseText);
if(results.success){
document.location.href="../home.jsp";
}
}
})
After running this code, I encountered the following error:
Uncaught Error: You're trying to decode an invalid JSON String:
The console.log output showed:
Object {request: Object, requestId: 1, status: 200, statusText: "OK", responseText: "↵↵↵↵↵"…}
To resolve this issue, I modified the code as follows (using URL to pass parameters):
Ext.Ajax.request({
url:'test.jsp?id=' + id + '&password=' + password,
success:function(response){
console.log(response);
var results = Ext.util.JSON.decode(response.responseText);
if(results.success){
document.location.href="../home.jsp";
}
}
})
Upon checking the console.log result after this change, it displayed:
Object {request: Object, requestId: 1, status: 200, statusText: "OK", responseText: "{success:true,msg:'success',url:'../main.jsp'}↵↵↵↵↵"…}
Following this adjustment, everything worked successfully.
Curious about why this alteration was necessary?