Himanshu Singh Himanshu Singh - 2 years ago 340
Javascript Question

Unexpected token < in JSON at position 4

var url="http://fsa.citop.in/lnct/service/signProcess.aspx";
var data={txtLogId: "abc@xyz.com",txtLogPass: "xyz",hdnReqType2: "sign87162"};
var success=function(data, textStatus, jqXHR) {

var fail=function(jqXHR, textStatus, errorThrown) {
console.log("Error:" + errorThrown );
type: "POST",
url: url,


This POST request gives me the error,
SyntaxError: Unexpected token < in JSON at position 4
, in the console of the page 'http://fsa.citop.in/lnct/' in chrome.

But if I use
(i.e. no http://), it gives me no error, but nothing comes back in data. On
of POST request, a JSON object is expected. Please somebody explain what is happening here and how it could be resolved.

Answer Source

It's most likely because the response is HTML and it's trying to parse it as something else. The < at position 4 is the first < of <!DOCTYPE html....

You should try to specify dataType in your ajax call (see http://api.jquery.com/jquery.ajax/) and also make signProcess.aspx to return something more useful (currently the response content type is application/json but it prints HTML).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download