I have created a class using an object as well as using Jquery 1.7.2. My Jquery for everything works fine EXCEPT AJAX related calls such as “$.ajax()” and “$.getJSON()”.
I usually don’t create classes via objects or functions because of not worrying about scope. I do think it’s a scope issue, but I’m not sure how to fix it since I have a good chunk of other Jquery code being used without a hitch. So the issue seems to be focused around Ajax is setup in JQuery.
Below is some of the Javascript code. Not all because it would be a massive amount, and all the Jquery uses in the rest of the code, such as binding(), click(), .each().
There is more to the HTML, as well as to the JavaScript that has everything working except the Ajax call. HTML, CSS, and Javascript have been validated. Which is why I keep thinking it’s a scope issue.
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="_res/css/main.css" />
<script src="_res/js/libs/jquery-1.7.2.min.js"></script>
<script src="_res/js/libs/main.js"></script>
</head>
<body></body>
</html>
Javascript Snippet Code (main.js)
var BettingApp = {
loadData:function()
{
//console.log("loadData()");
//BettingApp.resetData();
// This fails before it even tries to get the data.
$.ajax(
{
url: "/_res/json/sampleData.json",
cache: false,
contentType:"json",
processData: false,
complete: BettingApp.parseData,
success: BettingApp.parseData
});
},
resetData:function()
{
console.log("resetData()");
// This works just fine
$("#agencyBetView ul li").remove();
$("#playerBetView ul li").remove();
},
activateData:function()
{
console.log("activateData()");
}
};
$(document).ready(function(){ BettingApp.loadData(); });
Error from Browsers (Latest Chrome, Safari, Firefox)
Uncaught TypeError: Property 'String' of object [object Window] is not a function
jquery-1.7.2.min.js:2
e.extend.type jquery-1.7.2.min.js:2
f.Callbacks.n jquery-1.7.2.min.js:2
f.Callbacks.p.add jquery-1.7.2.min.js:2
f.extend.ajax jquery-1.7.2.min.js:4
BettingApp.loadData main.js:175
BettingApp.updateStep main.js:102
BettingApp.chooseBetType_agency main.js:369
f.event.dispatch jquery-1.7.2.min.js:3
f.event.add.h.handle.i
Jquery Functions Working in FULL Code
.bind()
.click()
.data()
.each()
.focus()
.focusout()
.html()
.ready()
.remove()
.slideUp()
.slideDown()
From the error
Property 'String' of object [object Window] is not a functionit means you overwrite window.String, as shown belowStringis actually being overwritten, by"fast"and at the very end by""You don’t need to specify variable types in javascript(actually you cant),I think this is what you meant