Results 1 to 4 of 4

Thread: Problem with View not updating when called with AJAX code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Problem with View not updating when called with AJAX code

    I'm hacking into the checkout functionality on a nopcommerce installation. The checkout on this uses a lot of ajax code calling in between the various checkout stages. I want to have them all stages seen at the same time but still keep the code that updates the models, for example when choosing a billing address from a drop down box.

    I'm at the stage now where I've removed the JSON code from the actionresult that gets called when you save an address and replaced it with view that should in theory reload the page. However, when I update the page, the view doesn't update with the new address. The previous details are still there. I have to refresh the page in the browser in order for it to update.

    I've checked the view in VS to make sure the variables are changing and getting rendered and they are. The only thing I can think is that the .NET framework is refusing to return anything back to the browser that isn't JSON code?

    I've tried to serialize and post the data using this javascript code:

    This is driving me absolutely nuts so please help me someone!
    Last edited by garry79; May 25th, 2014 at 12:02 PM.

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Problem with View not updating when called with AJAX code

    I'm at the stage now where I've removed the JSON code from the actionresult that gets called when you save an address and replaced it with view that should in theory reload the page. However, when I update the page, the view doesn't update with the new address. The previous details are still there. I have to refresh the page in the browser in order for it to update.
    Are you rendering a partial view inside a view? If yes, you need ajax so that you don't have to refresh the page. Why remove the JSON code?

    I've checked the view in VS to make sure the variables are changing and getting rendered and they are. The only thing I can think is that the .NET framework is refusing to return anything back to the browser that isn't JSON code?
    Maybe you can post some code snippets so others will be able to identify the issue.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Re: Problem with View not updating when called with AJAX code

    Quote Originally Posted by KGComputers View Post
    Are you rendering a partial view inside a view? If yes, you need ajax so that you don't have to refresh the page. Why remove the JSON code?



    Maybe you can post some code snippets so others will be able to identify the issue.
    Hi, yes, I'm rendering a partial view inside a view. I've even tried to RedirectToRoute to a different page and this just gets ignored.

    I may try using JSON on some of the checkout functionality but for adding a new address I would prefer to redirect to another page so I want to get this issue sorted anyway.

    Here's some code snippets:


    [ValidateInput(false)]
    public ActionResult OpcSaveBilling(FormCollection form)
    {
    // ...processes form data fine ...
    .
    // fails further down the method when attempt to redirect the page or return a new view. No //exception is invoked the page just stays as is
    return RedirectToRoute("cart");
    }

    Method is invoked on the front end this way:

    Code:
            $.ajax({
                cache: false,
                url: this.saveUrl,
                data: $(this.form).serialize(),
                type: 'post',
                success: this.nextStep,
                complete: this.resetLoadWaiting,
                error: Checkout.ajaxFailure
            });
    i've also tried this way but the method doesn't even get invoked:

    Code:
    	var data = $(this.form).serialize();
            $.post(url,data);

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Problem with View not updating when called with AJAX code

    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width