我正在尝试理解 javascript Promise 的概念。但我遇到了一些问题。我在本地设置了一个非常小的Web服务(不要生气,该Web服务不符合约定)。这里有一些关于它的细节
/login/<username>/<password>
==>登录系统,正确的用户名和密码都是noor
如果用户登录,则可以拨打电话/car/<brand>/<color>/<plate_number>
,
我没有对颜色、品牌、车牌号的类型进行任何验证
这个工作得很好,我正在记录并添加一辆车
$.ajax({type: "GET",url: url+"/login/noor/noor"})
.then(function( data, textStatus, jqXHR ) {console.log("login success");},function(){console.log("login error");})
.then($.ajax({type: "GET",url: url+"/car/1/1/1"}))
.then(function(){console.log("car added");},function(){console.log("car not added");});
这完美地显示了一个错误,因为使用了无效的 url:
$.ajax({type: "GET",url: url+"/carasdsad/1/1/1"})
.then(function(){console.log("car added");},function(){console.log("car not added");});
“/carasdsad/1/1/1”是无效网址并且车未添加被返回
我遇到了这个问题。下面的代码使用上面的代码。我正期待着车未添加待展示但它正在展示已添加汽车
$.ajax({type: "GET",url: url+"/login/noor/noor"})
.then(function( data, textStatus, jqXHR ) {console.log("login success");},function(){console.log("login error");})
.then($.ajax({type: "GET",url: url+"/carasdsad/1/1/1"}))
.then(function(){console.log("car added");},function(){console.log("car not added");});
上面的代码正在返回已添加汽车虽然“/carasdsad/1/1/1”第二次调用中的 url 无效。