I am trying to load the JSON data that I am getting from an aspx page into a drop down list that I have on another page but I am getting the following javascript error.
Microsoft JScript runtime error: 'SiteID' is null or not an object
The SiteID is not returning null though and I believe that is an object. The following is the code I am using to try and load the data into the drop down list:
The "sites" variable is getting a string of data back from the server. Now I need to get this data to load into the drop down list which isn't working for me. You got any ideas on how I can fix it?
usy
Member
14 Points
14 Posts
Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 09:11 AM|LINK
I am trying to load the JSON data that I am getting from an aspx page into a drop down list that I have on another page but I am getting the following javascript error.
Microsoft JScript runtime error: 'SiteID' is null or not an object
The SiteID is not returning null though and I believe that is an object. The following is the code I am using to try and load the data into the drop down list:
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">$.getJSON('Test.aspx?DepotID=' + DepotID, function (sites) {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> alert('test2');</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> $.each(sites, function (index, elem) {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> $("[id$='<%= ddlSiteName.clientid %>']").append($("<option></option>").val(elem.SiteID).text(elem.Site));</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> });</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> });</div>$.getJSON('Test.aspx?DepotID=' + DepotID, function (sites) {
alert('test2');
$.each(sites, function (index, elem) {
$("[id$='<%= ddlSiteName.clientid %>']").append($("<option></option>").val(elem.SiteID).text(elem.Site));
});
});
Can anyone help please?
Json JQuery & Asp.net
raghav_khung...
All-Star
32835 Points
5563 Posts
MVP
Re: Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 09:31 AM|LINK
Debug in firebug and put breakpoint over above line and see the values of elem. There must be null.
Anirudh.Gupt...
Member
633 Points
171 Posts
Re: Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 09:34 AM|LINK
Try this
$.getJSON('Test.aspx?DepotID=' + DepotID, function (sites) { alert('test2'); $.each(sites.d, function (index, elem) { $("[id$='<%= ddlSiteName.clientid %>']").append($("<option></option>").val(elem.SiteID).text(elem.Site)); }); });usy
Member
14 Points
14 Posts
Re: Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 09:43 AM|LINK
the value of elem appears to be null. Do you have any ideas how i can get the values into there?
raghav_khung...
All-Star
32835 Points
5563 Posts
MVP
Re: Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 09:46 AM|LINK
Yes thats what I said do one thing look whether you are getting any values in "sites" variable. If not then you are not getting data from server side.
usy
Member
14 Points
14 Posts
Re: Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 09:54 AM|LINK
The "sites" variable is getting a string of data back from the server. Now I need to get this data to load into the drop down list which isn't working for me. You got any ideas on how I can fix it?
raghav_khung...
All-Star
32835 Points
5563 Posts
MVP
Re: Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 09:57 AM|LINK
Please show the string which you are getting.
usy
Member
14 Points
14 Posts
Re: Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 10:02 AM|LINK
[{"SiteID":1682,"Site":1-3 EAST ROAD},{"SiteID":584,"Site":167 PINEWOOD STREET},{"SiteID":95,"Site":27 ELVETHAM HEATH WAY},]
raghav_khung...
All-Star
32835 Points
5563 Posts
MVP
Re: Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 10:12 AM|LINK
First of all you are missing quotes for the string type. The string should be
[{"SiteID":1682,"Site":"1-3 EAST ROAD"},{"SiteID":584,"Site":"167 PINEWOOD STREET"},{"SiteID":95,"Site":"27 ELVETHAM HEATH WAY"},]
usy
Member
14 Points
14 Posts
Re: Accessing JSON Data From an ASP.NET Page Using jQuery
Nov 19, 2010 10:19 AM|LINK
I've put speech marks around the string type but is is still giving me the "SiteID is null or not an object" error