嗨,伙计们。
当我尝试将ajax添加到JAX-WS服务(我使用的是googlejsonwebservice库)时,我遇到了一个问题。
所以在我的页面上我有这样的代码:
function submit(){
var JSONObject= '{sayHello:{name:"alexei"}}';
console.log(JSONObject);
$.ajax({
type: 'POST',
url: '/jaxwsExample-1.0.0-SNAPSHOT/json/hello',
contentType: 'application/json',
data: JSON.stringify(JSONObject),
dataType: 'application/json',
async: true,
success: function(data) {
console.log("DATA " + data);
}
});
}
和console.log(JSONObject);返回给我:
{sayHello:{name:"alexei"}}
但在我的TomCat服务器中,我遇到了以下错误:
原因:com.jaxws.json.codec.json错误:无效的json输入:“{sayHello:{name:\”alexei\“}}”
但我也从
http://code.google.com/p/jsonwebservice/wiki/GettingStarted
在该示例中,使用prototype.js框架进行了ajax调用:
function submit(){
new Ajax.Request('/jaxwsExample-1.0.0-SNAPSHOT/json/hello', {
method: 'post',
contentType: 'application/json',
postBody: '{"sayHello":{"name":"'+$('name').value+'"}}',
onSuccess: function(transport) {
$('response').update(transport.responseText).setStyle({ background: '#FFFFAA' });
$('notice').update(transport.responseText.evalJSON().message).setStyle({ background: '#dfd' });
}
});
}
但是我想使用jquery而不是prototype.js,你能帮我解决jquery ajax调用或JSON对象的问题吗?