f3b19c5dc98f28526aaa44f00adf9043c00ae83c
larrym
  Tue Oct 18 14:41:46 2011 -0700
make errorHandler error message less cryptic; simplify setCartVars by using POST so we don't have to chop-up long messages
diff --git src/hg/js/ajax.js src/hg/js/ajax.js
index 2b8b61b..5e79da5 100644
--- src/hg/js/ajax.js
+++ src/hg/js/ajax.js
@@ -1,31 +1,35 @@
 // AJAX Utilities
 
 var debug = false;
 
 var req;
 
 function nullProcessReqChange()
 {
     if(debug && this.readyState == 4)
             alert("req.responseText: " + req.responseText);
 }
 
+// The ajaxWaitCount code is currently NOT used, but we are keeping it in case in the future we decide we
+// really need to support sequential AJAX calls (without just using synchronous AJAX calls).
+// 
 // When setting vars with ajax, it may be necessary to wait for response before newer calls
 // Therefore this counter is set up to allow an "outside callback" when the ajax is done
 // The typical scenario is setCartVar by ajax, followed immmediately by a form submit.
 // To avoid the race condition, the form gets submitted after the ajax returns
+
 var ajaxWaitCount = 0;
 function ajaxWaitIsDone()     { return ( ajaxWaitCount <= 0 ); }
 function ajaxWaitCountUp()    { ajaxWaitCount++; }
 function ajaxWaitCountReset() { ajaxWaitCount = 0; }
 //function ajaxWaitCountShow()  { warn("ajaxWait calls outstanding:"+ajaxWaitCount); }
 
 // Here is where the "outside callback" gets set up and called
 var ajaxWaitCallbackFunction = null;
 var ajaxWaitCallbackTimeOut = null;
 function ajaxWaitCallbackRegister(func)
 { // register a function to be called when the ajax waiting is done.
     if(ajaxWaitIsDone())
         func();
     else {
         ajaxWaitCallbackFunction = func;
@@ -153,49 +157,46 @@
 {
 // Asynchronously sets the array of cart vars with values
     if(names.length <= 0)
         return;
 
     // Set up constant portion of url
     var loc = window.location.href;
     if(loc.indexOf("?") > -1) {
         loc = loc.substring(0, loc.indexOf("?"));
     }
     if(loc.lastIndexOf("/") > -1) {
         loc = loc.substring(0, loc.lastIndexOf("/"));
     }
     loc = loc + "/cartDump";
     var hgsid = getHgsid();
-    loc = loc + "?submit=1&noDisplay=1&hgsid=" + hgsid;
+    var data = "submit=1&noDisplay=1&hgsid=" + hgsid;
     var track = getTrack();
     if(track && track.length > 0)
-        loc = loc + "&g=" + track;
-
-    // Set up dynamic portion of url
-    var ix=0;
-    while( ix < names.length ) { // Sends multiple messages if the URL gets too long
-        var pairs = "";
-        for(  ;ix<names.length && pairs.length < 5000;ix++) {  // FIXME: How big is too big?
-            //pairs = pairs + "&cartDump.varName=" + escape(names[ix]) + "&cartDump.newValue=" + escape(values[ix]);
-            pairs = pairs + "&" + escape(names[ix]) + "=" + escape(values[ix]);
-        }
-        if(pairs.length == 0)
-            return;
-        //warn(pairs);
-        ajaxWaitCountUp();
-        loadXMLDoc(loc + pairs,ajaxWaitCountDown);
+        data = data + "&g=" + track;
+    for(var ix=0; ix<names.length; ix++) {
+        data = data + "&" + encodeURIComponent(names[ix]) + "=" + encodeURIComponent(values[ix]);
     }
+    $.ajax({
+               type: "POST",
+               url: loc,
+               data: data,
+               trueSuccess: function () {},
+               success: catchErrorOrDispatch,
+               error: errorHandler,
+               cache: false
+           });
 }
 
 function setCartVar(name, value)
 {
 // Asynchronously set a cart variable.
     setCartVars( [ name ], [ value ] );
 }
 
 function setVarsFromHash(varHash)
 {
 // Set all vars in a var hash
 // If obj is undefined then obj is document!
     var names = [];
     var values = [];
     for (var aVar in varHash) {
@@ -229,35 +230,37 @@
     $('form[name="mainForm"]').submit();
 }
 
 function setCartVarAndRefresh(name,val)
 {
     setCartVar(name,val);
     var main=$('form[name="mainForm"]')
     $(main).attr('action',window.location.href);
     setTimeout("submitMain()",50);  // Delay in submit helps ensure that cart var has gotten there first.
 
     return false;
 }
 
 function errorHandler(request, textStatus)
 {
-    var str = "encountered ajax error";
-    if(textStatus && textStatus.length) {
-        str += ": '" + textStatus + "'";
+    var str;
+    if(textStatus && textStatus.length && textStatus != "error") {
+        str = "Encountered network error : '" + textStatus + "'.";
+    } else {
+        str = "Encountered a network error."
     }
-    str += "; please retry the action you just performed";
+    str += " Please try again. If the problem persists, please check your network connection.";
     showWarning(str);
     jQuery('body').css('cursor', '');
     if(this.disabledEle) {
         this.disabledEle.attr('disabled', '');
     }
     if(this.loadingId) {
 	hideLoadingImage(this.loadingId);
     }
 }
 
 function catchErrorOrDispatch(obj, textStatus)
 {
 // generic ajax success handler (handles fact that success is not always success).
     if(textStatus == 'success')
         this.trueSuccess(obj, textStatus);