收到来自网络服务的回复时出现问题。请求和响应假设如下:
示例请求
{
"icno": "880808145588",
"password": "12345abcdejklll"
}
响应
{
"status": "0", //success=0, fail=1
"userId": 1
}
然后我尝试Postman,结果与上面类似。
但是如果我尝试使用我的移动应用程序(基于cordova),它会以其他方式返回,而不是我想要的。
结果
{"readyState":4,"responseText":"<html><head><title>Apache Tomcat/7.0.54 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - org.codehaus.jackson.JsonParseException: Unexpected character ('i' (code 105)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')</h1><HR size=\"1\" noshade=\"noshade\"><p><b>type</b> Exception report</p><p><b>message</b> <u>org.codehaus.jackson.JsonParseException: Unexpected character ('i' (code 105)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')</u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>javax.servlet.ServletException: org.codehaus.jackson.JsonParseException: Unexpected character ('i' (code 105)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@355a0e8e; line: 1, column: 2]\n\tcom.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)\n\tcom.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)\n\tcom.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:727)\n\torg.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n</pre></p><p><b>root cause</b> <pre>org.codehaus.jackson.JsonParseException: Unexpected character ('i' (code 105)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@355a0e8e; line: 1, column: 2]\n\torg.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432)\n\torg.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385)\n\torg.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306)\n\torg.codehaus.jackson.impl.Utf8StreamParser._handleUnexpectedValue(Utf8StreamParser.java:2084)\n\torg.codehaus.jackson.impl.Utf8StreamParser._nextTokenNotInObject(Utf8StreamParser.java:600)\n\torg.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:486)\n\torg.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2761)\n\torg.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2682)\n\torg.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308)\n\torg.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)\n\tcom.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)\n\tcom.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:483)\n\tcom.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)\n\tcom.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)\n\tcom.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)\n\tcom.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)\n\tcom.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)\n\tcom.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)\n\tcom.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\n\tcom.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)\n\tcom.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\n\tcom.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)\n\tcom.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1480)\n\tcom.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1411)\n\tcom.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1360)\n\tcom.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1350)\n\tcom.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)\n\tcom.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)\n\tcom.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)\n\tjavax.servlet.http.HttpServlet.service(HttpServlet.java:727)\n\torg.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/7.0.54 logs.</u></p><HR size=\"1\" noshade=\"noshade\"><h3>Apache Tomcat/7.0.54</h3></body></html>","status":500,"statusText":"Internal Server Error"}
我的js代码
$.ajax({
url: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
type: "POST",
contentType: 'application/json',
data: formData,
dataType: "json",
complete: function(data) {
$("#loading").hide();
if (data.status == 0) {
sessionStorage("userId", data.userId);
$("body").load(path + "pages/back/menuPage.html");
$.getScript(path + "js/back/menuPage.js", function() {
if (currentPage.init) {
currentPage.init();
}
});
} else {
navigator.notification.alert('No. kad pengenalan dan kata laluan tidak sah. ', null, 'Amaran', 'Ok');
}
}
});
请建议。
答案 0 :(得分:0)
我已经得到了答案
$.ajax({
url: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
type: "POST",
contentType: 'application/json',
data: formData,
dataType: "json",
complete: function(data) {
$("#loading").hide();
if (data.status == 0) {
sessionStorage("userId", data.userId);
$("body").load(path + "pages/back/menuPage.html");
$.getScript(path + "js/back/menuPage.js", function() {
if (currentPage.init) {
currentPage.init();
}
});
} else {
navigator.notification.alert('No. kad pengenalan dan kata laluan tidak sah. ', null, 'Amaran', 'Ok');
}
}
});