2012-12-14 99 views
0

我對ajax & Web服務稍微有點新鮮。我正在嘗試爲post方法做一個ajax調用。但我遇到了下面的錯誤。使用post方法的AJAX調用

The request sent by the client was syntactically incorrect(). </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":"[email protected]","abteilung":{"id":86,"isDeleted":null,"domainId":0,"parentId":85,"code":"mailCa","description":null},"authenticatedAccess":-1,"emailId":"[email protected]","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":"[email protected]","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":"[email protected]","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

+0

對於跨域ajax調用,可以使用JSONP。這是一個參考。 http://stackoverflow.com/questions/5141531/cross-domain-jquery-ajax-request – Hoque

+1

JavaScript代碼甚至不應該按照它的寫法運行,數據行應該會引發錯誤。 – epascarello

回答

1

周圍的data屬性的報價是錯誤的。你應該只發送一個簡單的JS對象,如

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

嗨菲爾我已經試過你的以上幾點,但我得到的錯誤爲ReferenceError:錯誤未定義 [Break On This Error] \t error(err); – Karthick88it

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": "[email protected]", 
      "abteilung": { 
       "id": 86, 
       "isDeleted": null, 
       "domainId": 0, 
       "parentId": 85, 
       "code": "mailCa", 
       "description": null 
      }, 
      "authenticatedAccess": -1, 
      "emailId": "[email protected]", 
      "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": "[email protected]", 
      "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": "[email protected]", 
       "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 
}); 
0

由於服務器所說,JSON是不正確的「格式化」。例如,

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

...的「前{不應該在那裏。(可能還有其他syntatic錯誤。)

您可以使用JSON驗證,如http://jsonlint.com/,來測試你的JSON 。載荷這會給你更多的細節有關的具體解析錯誤

0

您需要將正確的單/雙引號中的數據:

var yourData = { 
'id': 50, 
'isDeleted': 'N', 
'ownerId': { 
    'id': 32, 
    'fullName': 'mailAss,mailAss', 
    'status': 1, 
    'isDeleted': null, 
    'passWord': '[email protected]', 
    'abteilung': { 
     'id': 86, 
     'isDeleted': null, 
     'domainId': 0, 
     'parentId': 85, 
     'code': 'mailCa', 
     'description': null 
    }, 
    'authenticatedAccess': -1, 
    'emailId': '[email protected]', 
    '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': '[email protected]', 
    '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': '[email protected]', 
     '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" 
...