Link to home
Start Free TrialLog in
Avatar of Howard Bash
Howard BashFlag for United States of America

asked on

JavaScript Global Variable Access in Debugger

I created a variable (var Foobar) outside any JavaScript code within a script tag at the top of my html source.  I launch the page, press F12 to open the IE Debugging tool.  After that I go to the debugger's console tab and type Foobar expecting to see its current value.  The debugger comes back telling me that the variable is undefined.

I am trying to do this so I can use such a variable which has a JSON array assigned to it to parseJSON (Foobar) somewhere in a JavaScript function I need to build.

Any ideas about all this would be greatly appreciated
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Hi,
did you gave the variable an initial value?

If not then it is undefined.
var foobar;

Open in new window

==> Undefined

var foobar = '';

Open in new window

Should work.

HTH
Rainer
Avatar of Howard Bash

ASKER

I tried
var foobar = ''; and it didn't appear in debugger.  I am including entire HTML code here just in case there is something a bit more subtle I am missing.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQueryStuff</title>


<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<link rel="stylesheet" href="/resources/demos/style.css">

<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js"></script>

<script language="javascript" type="text/javascript" src="../../mydocs_TEMP/Alexandria/Projects/MEC/JSONUtilities.js"

<script language="javascript" type="text/javascript">

//My Foobar variable
var WPQ7ListData = '';

$( document ).ready(function() {
		//alert( "ready!" );
		
	$(function() {
	
		$( "#datepicker" ).datepicker();
	
	  });						

});
	
//JSON DATA
WPQ7ListData = { "Row" : 
[{
"ID": "189",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21- ELIMS",
"FileLeafRef": "189_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f189_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": " ccc Eliminations",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "190",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21001",
"FileLeafRef": "190_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002froperties\u002f190_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Tower",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "191",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21002",
"FileLeafRef": "191_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002erties\u002f191_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Tower 2",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "192",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21003",
"FileLeafRef": "192_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002roperties\u002f192_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Parking Garage",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "193",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21004",
"FileLeafRef": "193_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002froperties\u002f193_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Restaurant",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "194",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21005",
"FileLeafRef": "194_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002Properties\u002f194_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Conference",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "195",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21006",
"FileLeafRef": "195_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002Properties\u002f195_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Aq",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "196",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21007",
"FileLeafRef": "196_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002froperties\u002f196_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Smo",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "197",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21009",
"FileLeafRef": "197_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002roperties\u002f197_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Addr5",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "198",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21010",
"FileLeafRef": "198_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002Properties\u002f198_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Addr6",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "199",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21031",
"FileLeafRef": "199_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002fProperties\u002f199_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "North",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
],"FirstRow" : 1,
"LastRow" : 11
,"FilterLink" : "?FilterField1=Region&FilterValue1=New%20York&&PageFirstRow=1&"
,"FilterFields" : ";Region;"
,"ForceNoHierarchy" : "1"
,"HierarchyHasIndention" : ""

};


</script>

<script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  
</script>

</head>

<body>

<p>Date: <input type="text" id="datepicker"></p>


 

</body>
</html>

Open in new window

Hi,
in your HTML there are a couple of issues:
- Missing closing ">" and "</script>" in line 18
<script language="javascript" type="text/javascript" src="../../mydocs_TEMP/Alexandria/Projects/MEC/JSONUtilities.js"

Open in new window


- You load jQuery and jQuery UI two times in different versions - just load one version
- You run the datepicker function twice - you should run it only once
- Your WPQ7ListData array contains invalid / illegal characters (I am not sure which exactly) but at least Chrome and IE Debugging tools complained

The following updated HTML source finally works as expected:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQueryStuff</title>


<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<link rel="stylesheet" href="/resources/demos/style.css">

<script src="//code.jquery.com/jquery-2.1.4.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js"></script>

<script language="javascript" type="text/javascript" src="../../mydocs_TEMP/Alexandria/Projects/MEC/JSONUtilities.js"></script>

<script language="javascript" type="text/javascript">

//My Foobar variable
var WPQ7ListData = '';

$( document ).ready(function() {
		//alert( "ready!" );
		
	$(function() {
	
		$( "#datepicker" ).datepicker();
	
	  });						

});
	
//JSON DATA
WPQ7ListData = { "Row" : 
[{
"ID": "189",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21- ELIMS",
"FileLeafRef": "189_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f189_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": " ccc Eliminations",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "190",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21001",
"FileLeafRef": "190_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f190_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Tower",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "191",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21002",
"FileLeafRef": "191_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f191_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Tower 2",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "192",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21003",
"FileLeafRef": "192_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f192_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Parking Garage",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "193",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21004",
"FileLeafRef": "193_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002froperties\u002f193_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Restaurant",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "194",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21005",
"FileLeafRef": "194_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f194_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Conference",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "195",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21006",
"FileLeafRef": "195_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f195_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Aq",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "196",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21007",
"FileLeafRef": "196_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f196_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Smo",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "197",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21009",
"FileLeafRef": "197_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f197_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Addr5",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "198",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21010",
"FileLeafRef": "198_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f198_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Addr6",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "199",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21031",
"FileLeafRef": "199_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fSandbox\u002fLists\u002foperties\u002f199_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "North",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
],"FirstRow" : 1,
"LastRow" : 11
,"FilterLink" : "?FilterField1=Region&FilterValue1=New%20York&&PageFirstRow=1&"
,"FilterFields" : ";Region;"
,"ForceNoHierarchy" : "1"
,"HierarchyHasIndention" : ""

};


</script>

<script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  
</script>

</head>

<body>

<p>Date: <input type="text" id="datepicker"></p>


 

</body>
</html>

Open in new window


And finally: if you use the above code on a SharePoint site, please remember:
- Do not use "$" as shortcut to jQuery, this might be overwritten on SharePoint pages depending on the activated/used features. Always use "jQuery" explicitly.
- Do not use document.ready event - instead write your code into a function and push that one to the built in _spbodyonloadfunctionnames (variable depends on SharePoint version)

HTH
Rainer
Hi,

I cleaned up the code and have included it here.  The Doc Ready event doesn't show the alert message and that variable doesn't appear to be visible to the debugger.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQueryStuff</title>

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>

<script language="javascript" type="text/javascript" src="../../mydocs_TEMP/Alexandria/Projects/CNP/JSONUtilities.js" </script>

<script language="javascript" type="text/javascript">

var WPQ7ListData = '';

$(document).ready(function() {
		alert( "ready!" );		
});
	
//JSON DATA
WPQ7ListData = { "Row" : 
[{
"ID": "189",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21- ELIMS",
"FileLeafRef": "189_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f189_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "NY",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "190",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21001",
"FileLeafRef": "190_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f190_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "TW",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "191",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21002",
"FileLeafRef": "191_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f191_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "TE2",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "192",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21003",
"FileLeafRef": "192_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f192_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Garage",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "193",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21004",
"FileLeafRef": "193_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f193_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Cube",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "194",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21005",
"FileLeafRef": "194_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f194_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "center",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "195",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21006",
"FileLeafRef": "195_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f195_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "arium",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "196",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21007",
"FileLeafRef": "196_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f196_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "omplex",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "197",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21009",
"FileLeafRef": "197_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f197_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "NYr",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "198",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21010",
"FileLeafRef": "198_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f198_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "NYuu",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "199",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21031",
"FileLeafRef": "199_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f199_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "nt",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
],"FirstRow" : 1,
"LastRow" : 11
,"FilterLink" : "?FilterField1=Region&FilterValue1=New%20York&&PageFirstRow=1&"
,"FilterFields" : ";Region;"
,"ForceNoHierarchy" : "1"
,"HierarchyHasIndention" : ""

};


</script>

</head>

<body>

 

</body>
</html>

Open in new window

I tried your code and it does show the 'WPQ7ListData' in window as true.  However,  the value it shows is '',  and not that large JSON string.

I am guessing that some simple within it is causing that assignment to fail.  If so,  this is a bit of an issue as the JSON is produced by SharePoint.  So, I need to handle the bad character(s) to get to the point of passing this to parseJSON.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQueryStuff</title>

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>

<script language="javascript" type="text/javascript" src="../../mydocs_TEMP/Alexandria/Projects/CNP/JSONUtilities.js" </script>

<script language="javascript" type="text/javascript">

var WPQ7ListData = '';

$(document).ready(function() {
		alert( "ready!" );		
});
	
//JSON DATA
WPQ7ListData = { "Row" : 
[{
"ID": "189",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21- ELIMS",
"FileLeafRef": "189_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f189_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "NY",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "190",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21001",
"FileLeafRef": "190_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f190_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "TW",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "191",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21002",
"FileLeafRef": "191_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f191_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "TE2",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "192",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21003",
"FileLeafRef": "192_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f192_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Garage",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "193",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21004",
"FileLeafRef": "193_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f193_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "Cube",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "194",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21005",
"FileLeafRef": "194_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f194_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "center",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "195",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21006",
"FileLeafRef": "195_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f195_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "arium",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "196",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21007",
"FileLeafRef": "196_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f196_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "omplex",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "197",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21009",
"FileLeafRef": "197_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f197_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "NYr",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "198",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21010",
"FileLeafRef": "198_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f198_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "NYuu",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
,{
"ID": "199",
"PermMask": "0x7fffffffffffffff",
"FSObjType": "0",
"Title": "21031",
"FileLeafRef": "199_.000",
"Created_x0020_Date.ifnew": "",
"FileRef": "\u002fCNPSandbox\u002fLists\u002fCNPProperties\u002f199_.000",
"File_x0020_Type": "",
"File_x0020_Type.mapapp": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon": "",
"HTML_x0020_File_x0020_Type.File_x0020_Type.mapico": "icgen.gif",
"ContentTypeId": "0x010069518615D19E074DA43D189A28232A0A",
"Active": "Yes",
"Region": "New York",
"Address_x0020_": "nt",
"CalcMonth": "October",
"Modified": "10\u002f19\u002f2015 1:24 PM",
"Modified.FriendlyDisplay": "0|October 19",
"CalcYear": "2015"
}
],"FirstRow" : 1,
"LastRow" : 11
,"FilterLink" : "?FilterField1=Region&FilterValue1=New%20York&&PageFirstRow=1&"
,"FilterFields" : ";Region;"
,"ForceNoHierarchy" : "1"
,"HierarchyHasIndention" : ""

};


</script>

</head>

<body>

 

</body>
</html>

Open in new window

Hi,

"just" a simple typo:

Line 19
<script language="javascript" type="text/javascript" src="../../mydocs_TEMP/Alexandria/Projects/CNP/JSONUtilities.js" </script>

Open in new window

You miss the ">" at the end of the opening script tag.(after the src="...")

Should be
<script language="javascript" type="text/javascript" src="../../mydocs_TEMP/Alexandria/Projects/CNP/JSONUtilities.js"> </script>

Open in new window


JavaScript is very picky - one error and bumm.

HTH
Rainer
Just a comment on $(document).ready and $(function ... they are essentially the same thing.

You don't need both (I personally prefer $(function ... as it is shorter) - but you can shorten your code from this

$( document ).ready(function() {
  //alert( "ready!" );
    $(function() {

Open in new window


To this
$(function() {
 ... // JQuery code here
});

Open in new window

Hi,

Ok,  I put the right angle bracket on the script and now the alert message comes up and I can see my json variable when I type it's name into the console.

All good.  Now when I try to pass it to the parseJSON function it throws an error which I assume from what you previously mentioned is that some character in the json string is bad.  So,  I thought it was the back slash as that is an escape.  So I tried the following:

function GetPart(jdata) {	
	var jdataClean='';
	
	jdataClean = jdata.replace("\\", "\\\\");		
    var JSONDataObject = jQuery.parseJSON( jdataClean );	
}

Open in new window


The replace explodes and I don't get to the parseJSON call.
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
After all the smoke and dust settled that last question was the answer.  The variable already was the JSON object and I can iterate the row array and get the fields contained within.

Geeze.

Thank you sir!