0

我对 ajax 和 Web 服务有点陌生。我正在尝试对 post 方法进行 ajax 调用。但是我遇到了以下错误。

客户端发送的请求在语法上是错误的 ()。</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.25</h3></body></html>

但是 GET 方法运行良好。这是我尝试过的代码。

 $.ajax({
                type: "POST", //GET or POST or PUT or DELETE verb
                url: "http://88.80.223.163:8080/lumiin-service/lumiin/control/eventmap/add", // Location of the service
                data: "{"id":50,"isDeleted":"N","ownerId":{"id":32,"fullName":"mailAss,mailAss","status":1,"isDeleted":null,"passWord":"chandra20@gmail.com","abteilung":{"id":86,"isDeleted":null,"domainId":0,"parentId":85,"code":"mailCa","description":null},"authenticatedAccess":-1,"emailId":"chandra20@gmail.com1","uuid":"5988371662040","userCode":"mailAss","localOrg":null,"industryTypeId":{"name":"INSR","id":1,"isDeleted":"N","description":"Insurance"},"memeber":false,"profileType":"CA","lastName":"mailAss","firstName":"mailAss"},"prospectId":{"id":158,"isDeleted":"N","yearofBirth":null,"annualRevenue":0,"nationalityId":{"name":"CH","id":1,"isDeleted":"N","description":"Switzerland"},"titleId":{"name":"Mr","id":1,"isDeleted":"N","description":"Mr"},"maritalstatusId":null,"residencyId":null,"languageId":null,"priorityId":{"name":"High","id":2,"isDeleted":"N","description":"High"},"genderId":null,"abteilung":{"id":86,"isDeleted":null,"domainId":0,"parentId":85,"code":"mailCa","description":null},"emailId":"skmvilla@gmail.com","ownerId":{"id":31,"fullName":"mailCa,mailCa","status":0,"isDeleted":"N","passWord":"mailCa","abteilung":{"id":86,"isDeleted":null,"domainId":0,"parentId":85,"code":"mailCa","description":null},"authenticatedAccess":-1,"emailId":"chandra20@gmail.com1","uuid":null,"userCode":"mailCa","localOrg":null,"industryTypeId":{"name":"INSR","id":1,"isDeleted":"N","description":"Insurance"},"memeber":false,"profileType":"Manager","lastName":"mailCa","firstName":"mailCa"},"company":"company","statusId":{"name":"New","id":1,"isDeleted":"N","description":"New"},"startDate":null,"endDate":null,"lastName":"Search","firstName":"Search"},"eventId":{"URL":null,"location":null,"url":null,"id":92,"type":{"name":"govinda","id":20,"isDeleted":"N","description":"desc"},"isDeleted":"N","followUp":null,"countryId":null,"budget":0,"abteilung":{"id":86,"isDeleted":null,"domainId":0,"parentId":85,"code":"mailCa","description":null},"startDate":1337731200000,"endDate":1338422400000,"prospectId":null,"person":null,"eventName":"eeee-updated","place":null,"description":null}}", //Data sent to server                         
               //contentType: "application/json", // content type sent to server
                dataType: "json", //Expected data format from server
                processdata: true, //True or False
                success: function (json) {//On Successfull service call
                    //shell.loaded();
                    alert("cross domain ajax success full.");

                    var result = json.id;
                    alert("result===" + result);
                    $("#dvAjax").html(result);
                },
                error: ServiceFailed// When Service call fails
            });

如果有人知道请告知。提前致谢。

问候卡西克

4

4 回答 4

1

您的财产周围的报价data是错误的。您应该只发送一个简单的 JS 对象,例如

data: {"id": 50, "isDeleted": "N", ... },
dataType: 'json',
etc
于 2012-12-14T03:41:29.457 回答
0

尝试对发送的数据使用 JSON.stringify

$.ajax({
    type: "POST", //GET or POST or PUT or DELETE verb 
    url: "http://88.80.223.163:8080/lumiin-service/lumiin/control/eventmap/add", // Location of the service 
    data: JSON.stringify({
        "id": 50,
        "isDeleted": "N",
        "ownerId": {
            "id": 32,
            "fullName": "mailAss,mailAss",
            "status": 1,
            "isDeleted": null,
            "passWord": "chandra20@gmail.com",
            "abteilung": {
                "id": 86,
                "isDeleted": null,
                "domainId": 0,
                "parentId": 85,
                "code": "mailCa",
                "description": null
            },
            "authenticatedAccess": -1,
            "emailId": "chandra20@gmail.com1",
            "uuid": "5988371662040",
            "userCode": "mailAss",
            "localOrg": null,
            "industryTypeId": {
                "name": "INSR",
                "id": 1,
                "isDeleted": "N",
                "description": "Insurance"
            },
            "memeber": false,
            "profileType": "CA",
            "lastName": "mailAss",
            "firstName": "mailAss"
        },
        "prospectId": {
            "id": 158,
            "isDeleted": "N",
            "yearofBirth": null,
            "annualRevenue": 0,
            "nationalityId": {
                "name": "CH",
                "id": 1,
                "isDeleted": "N",
                "description": "Switzerland"
            },
            "titleId": {
                "name": "Mr",
                "id": 1,
                "isDeleted": "N",
                "description": "Mr"
            },
            "maritalstatusId": null,
            "residencyId": null,
            "languageId": null,
            "priorityId": {
                "name": "High",
                "id": 2,
                "isDeleted": "N",
                "description": "High"
            },
            "genderId": null,
            "abteilung": {
                "id": 86,
                "isDeleted": null,
                "domainId": 0,
                "parentId": 85,
                "code": "mailCa",
                "description": null
            },
            "emailId": "skmvilla@gmail.com",
            "ownerId": {
                "id": 31,
                "fullName": "mailCa,mailCa",
                "status": 0,
                "isDeleted": "N",
                "passWord": "mailCa",
                "abteilung": {
                    "id": 86,
                    "isDeleted": null,
                    "domainId": 0,
                    "parentId": 85,
                    "code": "mailCa",
                    "description": null
                },
                "authenticatedAccess": -1,
                "emailId": "chandra20@gmail.com1",
                "uuid": null,
                "userCode": "mailCa",
                "localOrg": null,
                "industryTypeId": {
                    "name": "INSR",
                    "id": 1,
                    "isDeleted": "N",
                    "description": "Insurance"
                },
                "memeber": false,
                "profileType": "Manager",
                "lastName": "mailCa",
                "firstName": "mailCa"
            },
            "company": "company",
            "statusId": {
                "name": "New",
                "id": 1,
                "isDeleted": "N",
                "description": "New"
            },
            "startDate": null,
            "endDate": null,
            "lastName": "Search",
            "firstName": "Search"
        },
        "eventId": {
            "URL": null,
            "location": null,
            "url": null,
            "id": 92,
            "type": {
                "name": "govinda",
                "id": 20,
                "isDeleted": "N",
                "description": "desc"
            },
            "isDeleted": "N",
            "followUp": null,
            "countryId": null,
            "budget": 0,
            "abteilung": {
                "id": 86,
                "isDeleted": null,
                "domainId": 0,
                "parentId": 85,
                "code": "mailCa",
                "description": null
            },
            "startDate": 1337731200000,
            "endDate": 1338422400000,
            "prospectId": null,
            "person": null,
            "eventName": "eeee-updated",
            "place": null,
            "description": null
        }
    }), //Data sent to server
    contentType: "application/json", // content type sent to server 
    dataType: "json", //Expected data format from server 
    processdata: true,  //True or False 

    success: function(json) { //On Successfull service call 
        //shell.loaded(); 
        // alert("cross domain ajax success full.");

        var result = json.id;
        alert("result===" + result);
        // $("#dvAjax").html(result);
    },
    error: ServiceFailed // When Service call fails
});
于 2012-12-14T03:44:17.257 回答
0

正如服务器所说,JSON 没有正确“格式化”。例如,

 data: "{"id":50,"isDeleted":"N"

... { 之前的 " 不应该在那里。(可能还有其他语法错误。)

您可以使用 JSON 验证器,例如http://jsonlint.com/来测试您的 JSON 有效负载。这将为您提供有关特定解析错误的更多详细信息。

于 2012-12-14T03:46:39.383 回答
0

您需要在数据中放置正确的单/双引号:

var yourData = {
'id': 50,
'isDeleted': 'N',
'ownerId': {
    'id': 32,
    'fullName': 'mailAss,mailAss',
    'status': 1,
    'isDeleted': null,
    'passWord': 'chandra20@gmail.com',
    'abteilung': {
        'id': 86,
        'isDeleted': null,
        'domainId': 0,
        'parentId': 85,
        'code': 'mailCa',
        'description': null
    },
    'authenticatedAccess': -1,
    'emailId': 'chandra20@gmail.com1',
    'uuid': '5988371662040',
    'userCode': 'mailAss',
    'localOrg': null,
    'industryTypeId': {
        'name': 'INSR',
        'id': 1,
        'isDeleted': 'N',
        'description': 'Insurance'
    },
    'memeber': false,
    'profileType': 'CA',
    'lastName': 'mailAss',
    'firstName': 'mailAss'
},
'prospectId': {
    'id': 158,
    'isDeleted': 'N',
    'yearofBirth': null,
    'annualRevenue': 0,
    'nationalityId': {
        'name': 'CH',
        'id': 1,
        'isDeleted': 'N',
        'description': 'Switzerland'
    },
    'titleId': {
        'name': 'Mr',
        'id': 1,
        'isDeleted': 'N',
        'description': 'Mr'
    },
    'maritalstatusId': null,
    'residencyId': null,
    'languageId': null,
    'priorityId': {
        'name': 'High',
        'id': 2,
        'isDeleted': 'N',
        'description': 'High'
    },
    'genderId': null,
    'abteilung': {
        'id': 86,
        'isDeleted': null,
        'domainId': 0,
        'parentId': 85,
        'code': 'mailCa',
        'description': null
    },
    'emailId': 'skmvilla@gmail.com',
    'ownerId': {
        'id': 31,
        'fullName': 'mailCa,mailCa',
        'status': 0,
        'isDeleted': 'N',
        'passWord': 'mailCa',
        'abteilung': {
            'id': 86,
            'isDeleted': null,
            'domainId': 0,
            'parentId': 85,
            'code': 'mailCa',
            'description': null
        },
        'authenticatedAccess': -1,
        'emailId': 'chandra20@gmail.com1',
        'uuid': null,
        'userCode': 'mailCa',
        'localOrg': null,
        'industryTypeId': {
            'name': 'INSR',
            'id': 1,
            'isDeleted': 'N',
            'description': 'Insurance'
        },
        'memeber': false,
        'profileType': 'Manager',
        'lastName': 'mailCa',
        'firstName': 'mailCa'
    },
    'company': 'company',
    'statusId': {
        'name': 'New',
        'id': 1,
        'isDeleted': 'N',
        'description': 'New'
    },
    'startDate': null,
    'endDate': null,
    'lastName': 'Search',
    'firstName': 'Search'
},
'eventId': {
    'URL': null,
    'location': null,
    'url': null,
    'id': 92,
    'type': {
        'name': 'govinda',
        'id': 20,
        'isDeleted': 'N',
        'description': 'desc'
    },
    'isDeleted': 'N',
    'followUp': null,
    'countryId': null,
    'budget': 0,
    'abteilung': {
        'id': 86,
        'isDeleted': null,
        'domainId': 0,
        'parentId': 85,
        'code': 'mailCa',
        'description': null
    },
    'startDate': 1337731200000,
    'endDate': 1338422400000,
    'prospectId': null,
    'person': null,
    'eventName': 'eeee-updated',
    'place': null,
    'description': null
}
};

然后使用:

...
data: yourData,
contentType: "application/json"
...
于 2012-12-14T03:57:29.107 回答