I am encountering a Uncaught SyntaxError: Unexpected end of input at the following code.
var dataURL = "LineChartController?tp=" + tpAtt + "&dept=" + dept + "&date=" + dateMY;
alert(dataURL);
var JSONdata = jQuery.ajax({
type: "GET",
url: dataURL,
async: false
}).responseText;
var psSeriesData2 = JSON.parse(JSONdata);
I am tried looking around and found no solution. These are the steps that I have taken.
Ensuring the JSONdata is correct – checked via http://www.jsonlint.com/ and
Ensuring that I have closed all brackets
The JSONdata is in the following format:
[{"Dates":["1-10","2-10","3-10","4-10","5-10","6-10","7-10","8-10"],"psScores":[78.78787878787878,79.7979797979798,78.78787878787878,78.78787878787878,78.78787878787878,79.7979797979798,79.7979797979798,76.92307692307693]}]
Another thing I did is that I am using prototype.js and other javascript libraries that cause an error,
Uncaught TypeError: Object function $(element) {
if (arguments.length > 1) {
for (var i = 0, elements = [], length = arguments.length; i < length; i++)
elements.push($(arguments[i]));
return elements;
}
if (Object.isString(element))
element = document.getElementById(element);
return Element.extend(element);
} has no method 'ajax'
I searched through forum and found that the solution is to change the $.ajax to jQuery.ajax, however, after that, the Uncaught SyntaxError: Unexpected end of input error appeared.
Appreciate any help on this issue. Any ideas what the problem is?
Is your server specifying a response type of application/json? If so, jQuery will automatically parse the result before it even gets back. Meaning, you’re trying to parse what’s already been parsed.
Try specifying the dataType in your call, and jQuery will pre-parse the result for you.
You should also try to do it asynchronously if possible.