简体   繁体   English

意外的令牌<在位置4的JSON中

[英]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) {
            console.log(data);
         };

var fail=function(jqXHR, textStatus, errorThrown) {
         console.log("Error:" + errorThrown );
     }
$.ajax({
  type: "POST",
  url: url,
  data:data,
  success:success,
  error:fail,

});

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. 此POST请求在chrome中的页面“ http://fsa.citop.in/lnct/ ”的控制台中向我提供错误, SyntaxError: Unexpected token < in JSON at position 4

But if I use fsa.citop.in/lnct/service/signProcess.aspx (ie no http://), it gives me no error, but nothing comes back in data. 但是,如果我使用fsa.citop.in/lnct/service/signProcess.aspx (即没有http://),它没有给我任何错误,但没有任何数据返回。 On success of POST request, a JSON object is expected. 在POST请求success时,需要一个JSON对象。 Please somebody explain what is happening here and how it could be resolved. 请有人解释这里发生了什么以及如何解决。

For those who encounter this problem in AWS Lambda code editor it is most likely your session has timed out. 对于那些在AWS Lambda代码编辑器中遇到此问题的人来说,您的会话很可能已超时。

Try reloading the page and signing in again. 尝试重新加载页面并再次登录。 It should resolve this. 它应该解决这个问题。

It's most likely because the response is HTML and it's trying to parse it as something else. 这很可能是因为响应是HTML,并且它试图将其解析为其他内容。 The < at position 4 is the first < of <!DOCTYPE html... . <位置4是第一个<!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). 你应该尝试在ajax调用中指定dataType(参见http://api.jquery.com/jquery.ajax/ ),并使signProcess.aspx返回更有用的东西(目前响应内容类型是application/json但它打印HTML)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM