有没有什么好点的工具使用js来访问rest webservice ?
要求能使用post方式访问, 并且能携带json类型的请求体 。 还要能处理返回的json内容
下面是我用jquery的ajax方法来请求的, 但是有一个问题。 服务端已经正确返回了,浏览器的response的responseStatus的值也是200 ,但是alert(success)不会执行,alert("error")和alert("complete");都会执行var getRecentlyURL = "http://localhost:8888/recently_post" ;
function requestRecentlyPOST(userId , lastPostId , content){
var content = genRequestBody(userId , lastPostId , content) ; //得到json字符串参数
$.ajax({
type: "POST",
url: getRecentlyURL ,
contentType :"text/plain; charset=UTF-8",
data:content
}).done(function() {
alert( "success" );
})
.fail(function(r) {
alert( "error" + r);
})
.always(function() {
alert( "complete" );
});
}
要求能使用post方式访问, 并且能携带json类型的请求体 。 还要能处理返回的json内容
下面是我用jquery的ajax方法来请求的, 但是有一个问题。 服务端已经正确返回了,浏览器的response的responseStatus的值也是200 ,但是alert(success)不会执行,alert("error")和alert("complete");都会执行var getRecentlyURL = "http://localhost:8888/recently_post" ;
function requestRecentlyPOST(userId , lastPostId , content){
var content = genRequestBody(userId , lastPostId , content) ; //得到json字符串参数
$.ajax({
type: "POST",
url: getRecentlyURL ,
contentType :"text/plain; charset=UTF-8",
data:content
}).done(function() {
alert( "success" );
})
.fail(function(r) {
alert( "error" + r);
})
.always(function() {
alert( "complete" );
});
}
解决方案 »
- SQL 查询语句解读 !!在线等待!!
- strut1的问题,显示不了数据
- @Entity 类中取得被映射成主键的属性
- hibernate3配置c3p0遇到的问题 APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
- 如何在jboss中运行mobicents?
- 用SSH开发系统时,异常如何进行处理?
- 网站一般都是根据什么来实现国际化?
- 500分紧急求助:用vb 开发一个J2EE的项目实例
- No ResultSet set was produced.异常
- 谁用JBOSS成功配置过MySQL,请帮帮我,我快疯了!
- 【求大神指点】请教如何将一个软件实现分布式编程
- struts2 跳转带参数,这样写可以吗?
///
success: function(msg) {
alert(msg);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
},
看看错误信息。
var content = genRequestBody(userId , lastPostId , content) ;
$.ajax({
type: "post",
contentType :"text/plain; charset=UTF-8",
url: getRecentlyURL,
data: content,
dataType: 'json',
success: function(result) {
alert(result);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
}); 进了error
alert的3个值依次是 0 、 0、 error
这个注释掉。试试看。
信息: 2013-10-31 17:08:48 127.0.0.1 - - 8888 POST /recently_post - 200 - 59 677 http://localhost:8888 Mozilla/5.0 (Windows NT 6.2; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0 -
但是就是js不行