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 4624896
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:11:42+00:00 2026-05-22T03:11:42+00:00

My connected sortables work great but I’m trying to make one improvement: If a

  • 0

My connected sortables work great but I’m trying to make one improvement:

If a user drags in item into the “#buttonmaker” sortable, I want the entire page to refresh.

What’s happening is if a user drags an item into the buttonmaker sortable, my ajax sorting.php page updates the database with a new menu button based off the item the user dropped in. After that, the page needs to be refreshed so the user can see the new menu button that they just created.

95% of the time though users will not be using the #buttonmaker and I don’t need a page refresh… ajax does it’s thing. It’s just for this one #buttonmaker container that I need a page refresh. Thanks for any help.

$(function() {
    $("#draft, #trash, #a_bunch_more_divs, #buttonmaker").sortable({
        connectWith: '.connectedSortable',
        placeholder: 'ui-state-highlight',
        opacity: 0.6,
        scroll: true,
        update : function () 
        { 
            $.ajax(
            {
                type: "POST",
                url: "sorting.php",
                data: 
                {
                    draft_sort:$("#draft").sortable('serialize'),
                    trash_sort:$("#trash").sortable('serialize'),
                    other_sort:$("#a_bunch_more_divs").sortable('serialize'),
                    buttonmaker_sort:$("#buttonmaker").sortable('serialize')
                }
            });
        }
    }).disableSelection();
});

Updated Code (I’ve changed a few cosmetic things since the original post):

$(function() {
    var refreshNeeded = false;
    $("#draft, #published, #trash").sortable({
        connectWith: '.connectedSortable',
        placeholder: 'ui-state-highlight',
        opacity: 0.6,
        scroll: true,
        update : function (event, ui) 
        { 
            var $sortable = $(this);
            if(ui.item.parent()[0] != this) return;
            var postData = {};
            postData[$sortable.attr('id') + '_sort'] = $sortable.sortable('serialize');
            if(ui.sender){
                postData[$sortable.attr('id') + '_sort'] = ui.sender.sortable('serialize');
            }
            $.ajax(
            {
                type: "POST",
                url: "js/post_sorting.php",
                data: postData,
                success: function() {
                    if(($sortable.attr('id') == "published")) refreshNeeded = true;
                    /*window.location.reload(true);*/
                }
            });
        }
    }).disableSelection();
    $(document).ajaxStop(function(){
        if(refreshNeeded){
            window.location.reload();
        }
    });
});
  • 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-22T03:11:43+00:00Added an answer on May 22, 2026 at 3:11 am

    It is always a good idea to check for the outcome of your ajax call. Also, sending the whole thing on every update is a waste of resources, as the update event gets called for both the source and the target sortable.

    As for the refresh, you just need to set a boolean variable whenever you think a refresh is needed, then bind an event to .ajaxStop() to run when all ajax requests have completed.

    $(function(){
        var refreshNeeded = false;
    
        $("#draft, #trash, #a_bunch_more_divs, #buttonmaker").sortable({
            connectWith: '.connectedSortable',
            placeholder: 'ui-state-highlight',
            opacity: 0.6,
            scroll: true,
            update : function(event, ui){
                var $sortable = $(this);
    
                // To avoid double-firing the event, return if it's not the sortable
                // where the item was dropped into.
                if(ui.item.parent()[0] != this) return;
    
                // Create object from the current sortable to post
                var postData = {};
                postData[$sortable.attr('id') + '_sort'] = $sortable.sortable('serialize');
    
                // If the item came from a connected sortable, include that in the post too
                if(ui.sender){
                    postData[ui.sender.attr('id') + '_sort'] = ui.sender.sortable('serialize');
                }
    
                $.ajax(
                {
                    type: "POST",
                    url: "sorting.php",
                    data: postData,
                    success: function(){
                        // What if we're all happy?
    
                        // If the triggering sortable was the buttonmaker, set the refresh flag
                        if($sortable.attr('id') == "buttonmaker")) RefreshNeeded = true;
                    },
                    error: function(){
                        // What if there is an error?
                    }
                });
            }
        }).disableSelection();
    
        $(document).ajaxStop(function(){
            // All requests have completed, check if we need to refresh
            if(refreshNeeded){
                // Refresh the page (just a simple reload for now)
                window.location.reload();
            }
        });
    });
    

    Edit: Added bit of code to only send current sortable in the post data. It assumes that the name of the data will always be id_sort, where id is the id of your sortable.

    Edit 2: Added some more bits to avoid double-firing the event, so it will only submit once per move. If item came from a connected sortable, it will include both sortables in the request.

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

Sidebar

Related Questions

Having troubles with items property of connected sortables. What I'm trying to do is
So I am trying to transfer over a div from one connected sortable container
I have several sortable lists connected together, so I can drag one item from
I have two connected sortable lists, but each one is in a larger block
I am trying to delete an <li> item using the this.remove() function but I
Clarification: I am trying to make the portlets sortable, but trying to connect them
This question is connected to my other question but I changed the logic a
I saw connected topic but... I was attempting to implement specification pattern. If I
I am trying to figure out the right regexp to match on list item
How do we handle connect draggable items that should be connected to sortables when

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.