使用post方法调用AJAX

时间:2012-12-14 03:29:45

标签: javascript jquery web-services

我对ajax& amp;网页服务。我正在尝试为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
            });

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

此致 Karthick

4 个答案:

答案 0 :(得分:1)

data属性周围的引号有误。你应该发送一个简单的JS对象,例如

data: {"id": 50, "isDeleted": "N", ... },
dataType: 'json',
etc

答案 1 :(得分: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
});

答案 2 :(得分:0)

正如服务器所说,JSON未正确&#34;格式化&#34;。例如,

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

...&#34;在{不应该在那之前。 (可能还有其他合成错误。)

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

答案 3 :(得分: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"
...