意外令牌<在JSON中的位置4 [英] Unexpected token < in JSON at position 4

查看:184
本文介绍了意外令牌<在JSON中的位置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,

});

此POST请求在页面' http://的控制台中给我错误SyntaxError: Unexpected token < in JSON at position 4. fsa.citop.in/lnct/'在Chrome中.

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.

但是如果我使用fsa.citop.in/lnct/service/signProcess.aspx(即没有http://),它不会给我带来任何错误,但数据不会返回任何内容.在POST请求的success上,需要一个JSON对象.请有人解释这里发生了什么以及如何解决.

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

推荐答案

最有可能是因为响应是HTML,并且正在尝试将其解析为其他内容.位置4上的<是第一个<的<!DOCTYPE html....

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....

您应该尝试在ajax调用中指定dataType(请参见 http://api.jquery.com /jquery.ajax/),并使signProcess.aspx返回更有用的内容(当前响应内容类型为application/json,但它会打印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).

这篇关于意外令牌&lt;在JSON中的位置4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆