I am learning dojo. My teller study application allows a user to enter some amount to deposite/withdraw from an account. It works perfectly fine in Firefox but ONLY ONCE in IE, with no error. I know it's not a problem with the back-end code, because I could enter the request url in the address bar and get the correct results.
spring-mvc to create TellerController; JsonView for returning the balance number as JSON; dojo.xhrGet for an ajax call.
Client-side:
function doDeposit() {
var toBeDeposited = document.getElementById("amount").value;
var args = {
methodName : "deposit",
amount : toBeDeposited
};
ajaxCall(args);
}
function ajaxCall(args) {
//request url: http://localhost:8084/LearnDojo/teller?methodName=deposit&amount=10.0
//return JSON: {"balance":220.0}
dojo.xhrGet({
url: "./teller",
handleAs: "json",
content: args,
load: displayBalance,
error: displayError
});
}
</javascript>
server-side:
<java>
//TellerController
public class BankTellerController extends MultiActionController {
private Account currentAccount;
public ModelAndView deposit(HttpServletRequest request,
HttpServletResponse response) {
String strAmount = request.getParameter("amount");
HashMap hashMap = new HashMap();
if (strAmount != null) {
double amount = Double.parseDouble(strAmount);
currentAccount.setBalance(currentAccount.getBalance() + amount);
hashMap.put("balance", currentAccount.getBalance());
}
return new ModelAndView(new JsonView(), hashMap);
}
public ModelAndView checkBalance(HttpServletRequest request,
HttpServletResponse response) {
HashMap hashMap = new HashMap();
hashMap.put("balance", currentAccount.getBalance());
return new ModelAndView(new JsonView(), hashMap);
}
}
//JsonView
public class JsonView implements View {
public void render(Map arg0, HttpServletRequest arg1,
HttpServletResponse arg2) throws Exception {
PrintWriter out = arg2.getWriter();
out.print(toJson(arg0));
out.flush();
}
}
var toBeDeposited = document.getElementById("amount").value;
var args = {
methodName : "deposit",
amount : toBeDeposited
};
ajaxCall(args);
}
function ajaxCall(args) {
//request url: http://localhost:8084/LearnDojo/teller?methodName=deposit&amount=10.0
//return JSON: {"balance":220.0}
dojo.xhrGet({
url: "./teller",
handleAs: "json",
content: args,
load: displayBalance,
error: displayError
});
}
</javascript>
server-side:
<java>
//TellerController
public class BankTellerController extends MultiActionController {
private Account currentAccount;
public ModelAndView deposit(HttpServletRequest request,
HttpServletResponse response) {
String strAmount = request.getParameter("amount");
HashMap hashMap = new HashMap();
if (strAmount != null) {
double amount = Double.parseDouble(strAmount);
currentAccount.setBalance(currentAccount.getBalance() + amount);
hashMap.put("balance", currentAccount.getBalance());
}
return new ModelAndView(new JsonView(), hashMap);
}
public ModelAndView checkBalance(HttpServletRequest request,
HttpServletResponse response) {
HashMap hashMap = new HashMap();
hashMap.put("balance", currentAccount.getBalance());
return new ModelAndView(new JsonView(), hashMap);
}
}
//JsonView
public class JsonView implements View {
public void render(Map arg0, HttpServletRequest arg1,
HttpServletResponse arg2) throws Exception {
PrintWriter out = arg2.getWriter();
out.print(toJson(arg0));
out.flush();
}
}

what about: ... xhrGet({
what about:
...
xhrGet({
url:"teller",
content: dojo.mixin(args,{ cacheBust:new Date().toString() });
...
});
to add a unique timestamp to each request?