ajax获取方法错误?未捕获的SyntaxError:意外的令牌< [英] ajax Get Method Error? Uncaught SyntaxError: Unexpected token <

查看:128
本文介绍了ajax获取方法错误?未捕获的SyntaxError:意外的令牌<的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function GetData() {
    var url = "http://localhost:60191/SampleService.asmx/SayHello";
    $.ajax({
        type: 'GET',
        url: url,
        crossDomain: true,
        contentType: "application/json; charset=utf-8",
        //data: "{firstName:'Aidy', lastName:'F'}",
        dataType: "jsonp",
        timeout: 4000,
        async: false,
        success: function (data) {
            debugger;

            var aa = JSON.parse(data);
            alert(data);
            $.each(msg, function (name, value) {
                alert(value);
                console.log(data.data);
            });
        },
        error: function (xhr, status, error) { alert('error 404 !!'); },
        async: false,
        cache: false
    });
}

推荐答案

.ajax({
type:' GET'
url:url,
crossDomain: true
contentType: application / json; charset = utf-8
// data:{firstName:'Aidy',lastName:'F'},
dataType: jsonp
timeout: 4000
async: false
成功: function (data){
debugger ;

var aa = JSON .parse(data);
al ert(data);
.ajax({ type: 'GET', url: url, crossDomain: true, contentType: "application/json; charset=utf-8", //data: "{firstName:'Aidy', lastName:'F'}", dataType: "jsonp", timeout: 4000, async: false, success: function (data) { debugger; var aa = JSON.parse(data); alert(data);


.each(msg, function (name,value){
alert(value) ;
console .log(data.data);
});
},
错误: function (xhr,status,error){alert('' 错误404 !!'); },
async: false
cache: false
} );
}
.each(msg, function (name, value) { alert(value); console.log(data.data); }); }, error: function (xhr, status, error) { alert('error 404 !!'); }, async: false, cache: false }); }


这可能是由你的JSON.parse引起的。



你不需要它。如果服务器告诉jQuery awnser是application / json。或者你告诉jQuery它是dataType:jsonp,

jQuery会为你解析数据。



现在你正在解析一个javascript对象。
It could be caused by your JSON.parse.

You do not need it. If the server tells jQuery the awnser is application/json. Or you tell jQuery it is dataType: "jsonp",
jQuery will parse the data for you.

So now you are parsing a javascript object.


这篇关于ajax获取方法错误?未捕获的SyntaxError:意外的令牌<的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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