Joseph Michael Pesch
VP Programming

Morris.js Charting Issue with Unresponsive JavaScript in Firefox Browser

by 9. January 2016 11:09

After implementing Morris.js for charting I would periodically receive this error message in Firefox:

Warning: Unresponsive script

A script on this page may be busy, 
or it may have stopped responding.  
You can stop the script now, 
open the script in the debugger, 
or let the script continue.

Script: http://.../plugins/morris/raphael.min.js


To resolve this I added the parseTime: false setting to the chart object. It seems that Mozilla tries to parse the "xLabels" attribute as a datetime and goes into a loop.

 

Tags:

JavaScript

JavaScript Testing Tools

by 25. September 2014 06:35

Tags:

JavaScript

jQuery $(document).ready() Not Working with ASP.Net UpdatePanel PostBack

by 27. September 2013 20:21

When using jQuery and $(document).ready() event along with an ASP.Net UpdatePanel the $(document).ready() event will only fire on the initial page load and will not fire on subsequent AJAX postbacks via the UpdatePanel.  There are a couple of common solutions posted to deal with this (shown below).  My preference is the first option which seems cleaner and has proven more reliable for me.

Solution 1:  Wrap the $(document).ready() event inside a pageLoad() function since the AJAX postback will always fire the pageLoad() event function.

function pageLoad() {
  $(document).ready(function () {
    DoPageInitialization();
  });
}

Solution 2:  Add a reference to the PageRequestManager and register your function to the add_endrequest() event.

$(document).ready(function() {
  // Still needed as the PageRequestManager below only fires on the postback...
  DoPageInitialization();
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function() {
  // Secondary binding for all AJAX postbacks through the UpdatePanel
  DoPageInitialization();
});

function DoPageInitialization() {
  ... Document Ready Code Here ...
}


Here is a good post that goes into more details on both $(document).ready() and pageLoad()
http://encosia.com/document-ready-and-pageload-are-not-the-same/

Tags:

ASP.Net | JavaScript | JQuery

Uploadify Issue with IE9 Button Not Triggering Browser to Upload

by 13. April 2013 23:18
Suffering issue wtih IE9 and Uploadify where the button that usually triggers the browse for file dialog does nothing.  It works if I switch to compatability mode but does nothing in standard mode.  I found some updated code below that fixes the issue, just replace the existing code in the jquery.uploadify.js and jquery.uploadify.min.js files.
SWFUpload.prototype.getFlashHTML = function () {
  // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  var obj = ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">'].join(""),
params = [
'<param name="wmode" value="', this.settings.button_window_mode, '" />',
'<param name="movie" value="', this.settings.flash_url, '" />',
'<param name="quality" value="high" />',
'<param name="menu" value="false" />',
'<param name="allowScriptAccess" value="always" />',
'<param name="flashvars" value="', this.getFlashVars(), '" />'
].join("");
  if (navigator.userAgent.search(/MSIE/) > -1) {
    obj = ['<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="', this.movieName, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">'].join("");
    params += '<param name="src" value="' + this.settings.flash_url + '" />';
  }
  return [obj, params, '</object>'].join("");
};

Tags:

JavaScript

Sys Undefined Exception in ASP.Net Web Form Menu Control Generated JS with URL Routing

by 16. October 2012 08:07

Although the exception only seems to occur when using URL routing it is not consistent (i.e. doesn't always happen).

The page generates this line at the end of the Form tag:

new Sys.WebForms.Menu({ element: 'Navigation Menu', disappearAfter: 500, orientation: 'horizontal', tabIndex: 0, disabled: false });

Throws JS runtime exception:

'Sys' is undefined

Solution:

void Application_Start(object sender, EventArgs e)
{
  RouteTable.Routes.Ignore("{resource}.axd");
}

Or:

  
<system.web>
  <pages controlRenderingCompatibilityVersion="3.5"/>
</system.web>

Tags:

ASP.Net | C# | JavaScript

JavaScript Drop Down Menu Example

by 18. May 2011 08:31

Tags:

CSS | HTML | JavaScript

HTML JavaScript Web Service Call

by 17. September 2010 14:56

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

  <title></title>

  <script type="text/javascript">

    function MakeSoapCall(WebServiceUrl, Namespace, WebMethod, WebMethodParams) {

      var xmlHttp;

      function SoapCall() {

        // creatng the xmlHttp object

        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

        // Calling the web service using post and true means asynchronous call

        // WebServiceUrl Sample: http://localhost/MyWebService.asmx

        xmlHttp.open("post", WebServiceUrl, true);

        // Setting the request header to let the web service identify the soap request we would be sending

        xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

        // SoapAction Sample: http://MyNameSpace.com/MyWebMethod – name of the webmethod

        // Example: [WebService(Namespace = "http://MyNameSpace.com/")] applied to our web service class

        xmlHttp.setRequestHeader("SOAPAction", "http://" + Namespace + "/" + WebMethod);

        xmlHttp.onreadystatechange = doUpdate;

        // setting the soap request body

        var soapRequest = "<?xml version='1.0' encoding='utf-8'?>" +

          "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +

          " xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +

          "<soap:Body>" +

          "<" + WebMethod + " xmlns='http://" + Namespace + "/'>" +

          WebMethodParams +

          "</" + WebMethod + ">" +

          " </soap:Body>" +

          "</soap:Envelope>";

        // send the request

        document.all('WebMethodParamsTextArea').value = soapRequest;

        xmlHttp.send(soapRequest);

        return false;

      }

      function doUpdate() {

        debugger;

        if (xmlHttp.readyState == 4) {

          var responseXMLResult = xmlHttp.responseXML;

          // var result = responseXMLResult.lastChild.nodeTypedValue;

          alert(responseXMLResult.xml);

        }

      }

      SoapCall();

    }

   

  </script>

</head>

<body>

  <form id="form1" runat="server">

  <div style="font-family: Calibri;">

    <table>

      <tr>

        <td>

          Web Service URL:

        </td>

        <td>

          <input type="text" id="WebServiceUrlControl" size="100" value="http://www.27seconds.com/Holidays/US/Dates/USHolidayDates.asmx" />

        </td>

      </tr>

      <tr>

        <td>

          Namespace:

        </td>

        <td>

          <input type="text" id="NamespaceControl" size="100" value="www.27seconds.com/Holidays/US/Dates" />

        </td>

      </tr>

      <tr>

        <td>

          Web Method:

        </td>

        <td>

          <input type="text" id="WebMethodControl" size="100" value="GetChristmasDay" />

        </td>

      </tr>

      <tr>

        <td valign="top">

          Web Method Paramaters:

        </td>

        <td>

          <textarea id="WebMethodParamsTextArea" rows="5" cols="75">

<year>2010</year>

          </textarea>

        </td>

      </tr>

      <tr>

        <td>

        </td>

        <td>

        </td>

      </tr>

    </table>

    <br />

    <input type="button" value="Make Soap Call" onclick="MakeSoapCall(document.all('WebServiceUrlControl').value, document.all('NamespaceControl').value, document.all('WebMethodControl').value, document.all('WebMethodParamsTextArea').value);" />

  </div>

  </form>

</body>

</html>

 

 

Tags:

HTML | JavaScript

MS CRM SOAP Call to WebService

by 1. September 2010 21:55

This sample would link to Client Address Zip Code field (onchange event) to find the State that corresponds to the zip code entered.

function Address1_PostalCode_OnChange() {

  var xmlHttp;

  function SoapCall() {

    // Get zip code from screen field

    var oField = event.srcElement;

    var zipCode = "";

    if (typeof (oField) != "undefined" && oField != null) {

      zipCode = oField.value;

    }

 

    // creatng the xmlHttp object

    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

    // Calling the web service using post and true means asynchronous call

    xmlHttp.open("post", "http://mysite.com/ZipCountyWS/ZipCountyWS.asmx", true);

    // Setting the request header to let the web service identify the soap request we would be sending

    xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    // http://mynamespace.com/GetStateAndCountyByZipCode – name of the webmethod

    //[WebService(Namespace = "http://mynamespace.com/")] which we had applied to our web service class

    xmlHttp.setRequestHeader("SOAPAction", "http://mynamespace.com/GetStateAndCountyByZipCode");

    xmlHttp.onreadystatechange = doUpdate;

    // setting the soap request body

    var soapRequest = "<?xml version='1.0' encoding='utf-8'?>" +

          "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +

          " xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +

          "<soap:Body>" +

          "<GetStateAndCountyByZipCode xmlns='http://mynamespace.com/'>" +

          "<ZipCode>" + zipCode + "</ZipCode> " +

          "</GetStateAndCountyByZipCode>" +

          " </soap:Body>" +

          "</soap:Envelope>";

    // send the request

    xmlHttp.send(soapRequest);

    return false;

  }

  function doUpdate() {

    debugger;

    if (xmlHttp.readyState == 4) {

      var responseXMLResult = xmlHttp.responseXML;

      var result = responseXMLResult.lastChild.nodeTypedValue;

      crmForm.address1_stateorprovince.value = '';

      crmForm.address1_county.value = '';

      if (result.indexOf('UNKNOWN') == -1) {

        crmForm.address1_country.value = 'USA';

      }

      else {

        alert('Please confirm zip code: '

        + crmForm.address1_postalcode.value

        + ' is valid, no county record was found.'

        + '\r'

        + 'If this is a valid zip code please alert the system administrator.'

      );

      }

      crmForm.address1_stateorprovince.value = result.split(':')[0];

      crmForm.address1_county.value = result.split(':')[1];

    }

  }

  SoapCall();

}

 

 

Tags:

JavaScript | MS CRM

JavaScript Check for Undefined Variable (null value)

by 25. August 2010 15:51

if (typeof (myVar) != "undefined" && myVar != null) {

  alert('myVar is defined');

}

Tags:

JavaScript

JavaScript getElementsByClassName() Function

by 24. February 2010 16:09

Function from: http://robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/

function getElementsByClassName(className, tag, elm){
  var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
  var tag = tag || "*";
  var elm = elm || document;
  var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
  var returnElements = [];
  var current;
  var length = elements.length;
  for(var i=0; i<length; i++){
    current = elements[i];
    if(testClass.test(current.className)){
      returnElements.push(current);
    }
  }
  return returnElements;
}

Tags:

JavaScript