"Expecting More Source Characters" in my Javascript
Visual Studio is objecting to the script below and returns a message that says "Expecting More Source Characters". This I assume is the reason this script won't fire on the page.
Usually when I get this message in VS it means I forgot a semi colon. However I don't think that is the case this time. What could be causing this error?
jQuery(document).ready(function ($) {
var Category = "animals";
va开发者_运维百科r BaseURL = "http://localhost:61741/VocabGame/play?cat=";
var URL = BaseURL + Category;
$.getJSON(URL, {
tags: "Pinyin",
tagmode: "any",
format: "json"
},
function (data) {
$('#ChoiceA').append = data.nouns[0].Pinyin;
$('#ChoiceB').append = data.nouns[1].Pinyin;
});
jQuery(function($) {
var category = "animals",
baseURL = "http://example.com/?cat=",
url = baseURL + category;
$.getJSON(url, {tags: "Pinyin", tagmode: "any", format: "json"},
function(data) {
...
}
);
}); // This line is missing from your code.
Note also that the convention in JavaScript is to capitalize your classes. Thus, I did not capitalize the variables in this example.
I think you're missing the closing })
and also have a problem with your .append()
lines. Try this:
jQuery(document).ready(function ($) {
var Category = "animals";
var BaseURL = "http://localhost:61741/VocabGame/play?cat=";
var URL = BaseURL + Category;
$.getJSON(URL, {
tags: "Pinyin",
tagmode: "any",
format: "json"
}, function (data) {
$('#ChoiceA').append(data.nouns[0].Pinyin);
$('#ChoiceB').append(data.nouns[1].Pinyin);
});
});
精彩评论