Error running Javascript Generated

Feb 15, 2013 at 8:05 PM
Hi,

I've used the query designer to generate some javascript code. I can see the XML data in Internet Explorer when I browse to the URL. The problem is when I put the Javascript code into a OnChange event in my form. It states:

"OData Execution Error Occurred"

This is the code I am using:
RetrieveRecords : function(new_MonthofQuestionnaire){
var query = "/IncidentSet?$select=new_ADR,new_ADR2011,new_ADRVariance&$orderby=ContactId asc&$filter=new_MonthofQuestionnaire/Value eq "+new_MonthofQuestionnaire+"";
ExecuteQuery(query);
}
//
// ExecuteQuery executes the specified OData Query asyncronously
//
// NOTE: Requires JSON and jQuery libraries. Review this Microsoft MSDN article before
// using this script http://msdn.microsoft.com/en-us/library/gg328025.aspx
//
function ExecuteQuery(ODataQuery) {
var serverUrl = Xrm.Page.context.getServerUrl();

// Adjust URL for differences between on premise and online 
if (serverUrl.match(/\/$/)) {
    serverUrl = serverUrl.substring(0, serverUrl.length - 1);
}

var ODataURL = serverUrl + "/XRMServices/2011/OrganizationData.svc" + ODataQuery;

$.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: ODataURL,
    beforeSend: function (XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
    },
    success: function (data, textStatus, XmlHttpRequest) {
        //
        // Handle result from successful execution
        //
        // e.g. data.d.results
    },
    error: function (XmlHttpRequest, textStatus, errorObject) {
        //
        // Handle result from unsuccessful execution
        //
        alert("OData Execution Error Occurred");
    }
});
}

//
// Error Handler
//
function ErrorHandler(XMLHttpRequest, textStatus, errorObject)
{ alert("Error Occurred : " + textStatus + ": " + JSON.parse(XMLHttpRequest.responseText).error.message.value); }
Any insight as to why this isn't working correctly?

Thanks,

Devin