Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7573429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:10:48+00:00 2026-05-30T16:10:48+00:00

I am trying to make my page reload after sorting through the new position,

  • 0

I am trying to make my page reload after sorting through the new position, either through Javascript or in the Ruby on Rails code.

$("#serialize").click ->
c = set: JSON.stringify($("#sortable").nestedSortable("toHierarchy",
  startDepthCount: 0
))
$.post "savesort", c, $("#output").html("<p id=\"flash_notice\">Saved Successfully</p>")
false

I’m thinking of adding it here

$.post "savesort", c, $("#output").html("<p id=\"flash_notice\">Saved Successfully</p>")
window.location.reload(false); 
false

But it seems like that messes up the order. Here is my rails code

class SiteController < ApplicationController

def savesort
neworder = JSON.parse(params[:set])
prev_item = nil
neworder.each do |item|
  dbitem = Category.find(item['id'])
  prev_item.nil? ? dbitem.move_to_root : dbitem.move_to_right_of(prev_item)
  sort_children(item, dbitem) unless item['children'].nil?
  prev_item = dbitem   
end
Category.rebuild!
render :nothing => true
  end
end

I am also thinking about change render :nothing => true to redirect_to root_url but that doesn’t seem to work either.

here is my Routes.rb (Shortened for the sake of space)

locksmithing::Application.routes.draw do
  get "site/home"
  match "/savesort" => 'site#savesort'
    root to: 'site#home'
end

So, where should I add the code to refresh the page? Javascript or in the Site Controller? or is there another solution? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:10:50+00:00Added an answer on May 30, 2026 at 4:10 pm

    First of all, your $.post call doesn’t do what you’re probably expecting it to. This:

    $.post "savesort", c, $("#output").html("<p id=\"flash_notice\">Saved Successfully</p>")
    

    is the same as this:

    $.post "savesort", c
    

    I think your intent is to execute $('#output').html() when the asynchronous $.post call finishes but you need a callback function for that. This part of your $.post:

    $("#output").html("<p id=\"flash_notice\">Saved Successfully</p>")
    

    will execute while the $.post call is being built and its return value will be a jQuery object which $.post won’t know what to do with. To fix that, just wrap your callback in, well, a callback:

    $.post "savesort", c, ->
        $("#output").html("<p id=\"flash_notice\">Saved Successfully</p>")
    

    If you put your window.location.reload(false) immediately after your $.post then you’ll reload the page before the POST completes and that’s probably not what you want to do and that would explain your “messed up order” problem. Try moving that into the $.post callback so that it will execute after the POST has completed:

    $.post "savesort", c, ->
        $("#output").html("<p id=\"flash_notice\">Saved Successfully</p>")
        window.location.reload(false)
    

    Your original code was ignoring the response from SiteController#savesort completely so it wouldn’t matter if it returned nothing, returned something, or redirected. The above callback changes still ignore what the controller returns but that’s okay and :nothing => true is a sensible thing for it do.

    Once you have all that working, you could replace the reload by having your controller return the new data to insert into the page and then the $.post callback could insert that new data into the page. That would be a pretty standard AJAX approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a page that shows how to enable JavaScript in various
I'm using jquery.mobile-1.0.1. I'm trying to make the page reload when clicking on the
I have been trying to make a page which combines web.py and JavaScript, and
trying to make a page which will recursively call a function until a limit
I'm trying to make a page in php that takes rows from a database,
I am trying to make a php login page that allows users to access
Here is a page I am trying to make print friendly, so it will
I'm trying to make a web scraper that will parse a web-page of publications
I'm trying to make it so that a form submit doesn't cause the page
I'm trying to make a WordPress site that has six lists on a page,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.