0

从我的 OnePageCheckout.cshtml 视图中,我调用 ajax 控制器

@Html.Hidden("StepContent", (string)ViewBag.newAddress)  @* never work *@
$.ajax({
    cache: false,
    url: this.saveUrl,
    data: $(this.form).serialize(),
    type: 'post',
    success: this.nextStep,  // still stay in the same page
    complete: this.resetLoadWaiting,
    error: Checkout.ajaxFailure
});
public ActionResult OpcSaveBilling(FormCollection form) {    
    ViewBag.newAddress="abc";
    return Json(new {
        update_section = new UpdateSectionJsonModel() {
            name = "confirm-order",
            html = this.RenderPartialViewToString("OpcConfirmOrder",  confirmOrderModel)
        },
        goto_section = "confirm_order"
    });
}

如何使用来自控制器的值更新隐藏输入的状态?

更新 2:

var Billing = {
form: false,
saveUrl: false,

init: function (form, saveUrl) {
    this.form = form;
    this.saveUrl = saveUrl;
},



save: function () {
    if (Checkout.loadWaiting != false) return;

    Checkout.setLoadWaiting('billing');

    $.ajax({
        cache: false,
        url: this.saveUrl,
        data: $(this.form).serialize(),
        type: 'post',
        success: function (data) {
            this.nextStep;   << nextStep won't be called !!  but it works for success:  this.nextStep
        },
        complete: this.resetLoadWaiting,
        error: Checkout.ajaxFailure
    });


},

resetLoadWaiting: function () {
    Checkout.setLoadWaiting(false);
},

nextStep: function (response) {
    alert('aa');
    if (response.error) {
        if ((typeof response.message) == 'string') {
            alert(response.message);
        } else {
            alert(response.message.join("\n"));
        }

        return false;
    }
    $('#StepContent').val($("#billing-address-select").find('option:selected').text());

    Checkout.setStepResponse(response);
}

};

4

1 回答 1

0

ajax调用后更改JS中的状态,

$.ajax({
    cache: false,
    url: this.saveUrl,
    data: $(this.form).serialize(),
    type: 'post',
    success: function (data) {
          $("#StepContent").val(data.status);
           this.nextStep;        
    },  
    complete: this.resetLoadWaiting,
    error: Checkout.ajaxFailure
});

和控制器在 JSON 中传递状态

public ActionResult OpcSaveBilling(FormCollection form) {    
    ViewBag.newAddress="abc";
    return Json(new {
        update_section = new UpdateSectionJsonModel() {
            name = "confirm-order",
            html = this.RenderPartialViewToString("OpcConfirmOrder",  confirmOrderModel),            
        },
        status = "abc",
        goto_section = "confirm_order"
    });
}
于 2013-11-06T09:40:05.763 回答