This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



May 21, 2012, 8:14 PM
24 Posts
topic has been resolvedResolved

Client side JavaScript stops running without finishing JSON parsing

  • Category: Dojo and Client Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 2
I have this JavaScript behind a button on a custom control which was working last week and now does not -- there have been no code changes.
 
Here is the code:
var url = "http://myurl.com";     // generic url...
var returnValues;
var jsonValues;
var jsonName;
var jsonValue;
var xhr;
var doc = document.forms[0];

if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open("GET", url, true);
xhr.send(null);
xhr.onreadystatechange = function (){
                if (xhr.readyState == 4) {                                                               
                    if (xhr.status == 200) {
                        returnValues = xhr.responseText;
                        jsonValues = eval('(' + returnValues + ')');
                        for (i = 0; i < jsonValues.items.length; i++) {
                            jsonName = jsonValues.items[i].name;
                            jsonValue = jsonValues.items[i].value;
                            if (jsonName == "name") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Name1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                            }
                            if (jsonName == "job") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Title1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                            }
                            if (jsonName == "loc") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Location1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                            }
                            if (jsonName == "mail") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Email1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                            }
                            if (jsonName == "phone") {
                                for(var x = 0; x < doc.elements.length; x++){
                                        if(document.forms[0].elements[x].name=="#{id:sr_Phone1}" ){
                                            document.forms[0].elements[x].value = jsonValue;
                                        }
                                }
                            }

                        }

                }
            }                                                            
        }; 
 
It will cycle through 2 of the JSON value even though there are over 20 of them -- it stops with no errors or messages...
 
Any ideas would be great...
 
Thanks!
Dan
May 22, 2012, 7:43 AM
126 Posts
Re: Client side JavaScript stops running without finishing JSON parsing
Have you tried putting it in a try / catch to see is there a json parse error or reference error that maybe isn't getting picked up ?
 
also have you checked what the value of 
 
jsonValues.items.length
 
is in the main for loop? 
 
and checking each: 
doc.elements.length 
 
could be something odd going with them. I'd put in some print outs " console.log("Length: " + ...); " and see the values / where its stopping.
May 22, 2012, 2:36 PM
24 Posts
Re: Client side JavaScript stops running without finishing JSON parsing
In my code, I was missing
var doc = document.forms[0];
 
Added that and it worked great...
 
My mistake...

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal