W
W
wkololo_4ever2014-05-01 10:09:18
JavaScript
wkololo_4ever, 2014-05-01 10:09:18

Why is the Unexpected end of input error displayed?

There is a code

var request = new XMLHttpRequest();
    request.open("GET", "/Home/Test", true);   
    request.onprogress = function () {
        var pol = request.responseText;
        var k = JSON.parse(pol);
    }
    request.send(null);

Chrome throws an "Unexpected end of input" error. I can't figure out what it has to do with it. If you remove the line , the error disappears. What am I writing wrong? PS: I once encountered this error when I forgot to put "}", but now everything seems to be in its place. UPD: Everything works in IE. What is all this connected with? UPD2 : controller codevar k = JSON.parse(pol);


public JsonResult Test()
        {
            return Json(new { name = "Вова", secondName = "Иванов" },JsonRequestBehavior.AllowGet);
        }


UPD3: I solved the problem , I forgot to add a check IE and Chrome handle the onprogress event differently. request.readyState === 4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rostislav Grigoriev, 2014-05-01
@crazyzubr

I will turn on the telepathy module and assume that the script that gives the answer is a php script. In this case, it is probably saved with utf8 encoding with BOM, or the output contains extra line breaks.
The solution is to resave the file in utf8 without BOM or exclude line breaks, respectively.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question