简体   繁体   English

Javascript-处理来自Web服务的AJAX呼叫响应

[英]Javascript - Handling a AJAX call response from a web service

I'm using Javascript and Jquery to call a web service. 我正在使用Javascript和Jquery调用Web服务。 The service should return an object. 服务应返回一个对象。 If the object returned contains Result=0, I want to show an alert, and if it doesn't, I want to show a different alert. 如果返回的对象包含Result = 0,则我想显示一个警报,否则,我想显示另一个警报。

My code is shown below. 我的代码如下所示。 I've tried "if (data.Result)" and "if (data.Result=0)", and neither of them work and show the "stock added" popup message. 我尝试了“ if(data.Result)”和“ if(data.Result = 0)”,但它们都不起作用,并显示“已添加库存”弹出消息。

Any help would be appreciated. 任何帮助,将不胜感激。

Object returned: 返回的对象:

data: Object
Booking: Object
BookingId: "28eec5f6-29a7-e411-941a-00155d101201"
BookingProductIds: null
BookingStatus: 2
CrossSellProducts: null
ErrorMessage: ""
Result: 0

Javascript code: JavaScript代码:

    function generateOrder() {
        ABC.TixService.AddStockProduct(null, null, productRequest, ticketingRequest, function (context, data) {
            if (data.Result) {
                alert("stock added");
            }
            else
                alert("error");
        });



AddStockProduct: function (context, bookingId, productRequests, request, action) {
    $.ajax({
        url: 'TixService.svc/AddStockProduct',
        cache: false,
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json',
        data: JSON.stringify({ bookingId: bookingId, productRequests: productRequests, request: request }),
        context: { context: context, action: action },
        success: function (data) {
            this.action(this.context, data.AddStockProductResult);

        },
        error: function (xhr, ajaxOptions, thrownError) {
            ErrorResponse(xhr, thrownError);
        }
    });
},

Shouldn't the test be: 测试不应该是:

 if(data.Result === 0){
     alert('stock added');
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM