Jquery ajax 在调用 rest Web 服务时失败
Jquery ajax fail when calling rest webservice
我有一组 REST URI,我可以在服务器上进行身份验证后访问它们。此服务采用包含登录信息的 JSON 输入,并使用会话 ID 检索 JSON 输出。
使用 Rest 客户端(如 chrome 扩展程序)时,一切正常。
现在我想使用 JS 实现它,但尽管返回失败,但我看不到错误的任何详细信息(错误消息为空白),也找不到我在代码中缺少的内容。
$.ajax({
// the URL for the request
url: "https://host002:50000/b1s/v1/Login",
// the data to send (will be converted to a query string)
data: {
UserName: "manager",
Password: "1234",
CompanyDB: "CUS_001"
},
// whether this is a POST or GET request
type: "POST",
// the type of data we expect back
dataType : "json",
// code to run if the request succeeds;
// the response is passed to the function
success: function( json ) {
$( "<h1/>" ).text( json.title ).appendTo( "body" );
$( "<div class='"content'"/>").html( json.html ).appendTo( "body" );
},
// code to run if the request fails; the raw request and
// status codes are passed to the function
error: function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem! " + xhr.responseText);
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
},
// code to run regardless of success or failure
complete: function( xhr, status ) {
alert( "The request is complete!" );
}
});
xhr.responseText 始终为空。状态始终为错误。errorThrow也始终为空。
我也尝试了$post方法,但得到了相同的行为。
您的 JSON 不正确。尝试使用这个
data: JSON.stringify({UserName: "manager", Password: "1234", CompanyDB: "CUS_001"});
从一个 url 导航到另一个 url 时,会弹出一个跨域错误。尝试这样做。使用 ajax 调用同一 url 上的函数,并从那里使用 CURL 请求到您的 Web 服务 url。
相关文章:
- Jasmine单元测试在监视服务方法时失败
- 当服务失败时,如何解析状态
- AngularJS中共享数据服务初始化失败
- AngularJS注入服务失败
- 从jQuery调用Web服务失败适用于python
- $cacheFactory removeAll() 在服务中的单元测试在 Angular 1.2.0 中失败,但在 1.
- 在 angularJS 中向控制器注入服务失败
- Ajax 对 Web 服务 Aways 的调用失败
- Jquery ajax 在调用 rest Web 服务时失败
- 节点脚本需要向调用它的 Angular 服务返回成功/失败
- 谷歌地图方向服务有时会失败
- 使用谷歌地图api在移动设备上的地理定位服务失败
- 当服务抛出错误时,$httpBackend.flush失败
- $.ajax函数在向web服务发送JSON对象时失败
- 在谷歌地图API 3中清除方向服务的路由失败
- 将工厂注入服务失败
- AngularJS, Jasmine服务测试注入失败
- Angular自定义服务调用失败
- Dynamic Directive元素在来自服务的预填充数据中失败
- 将数据发送到本地服务 jQuery 在 IE 中失败