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

  • Home
  • SEARCH
  • 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 7557813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:13:49+00:00 2026-05-30T12:13:49+00:00

I have a sortable list using JQueryUI and use the JQuery Each function to

  • 0

I have a sortable list using JQueryUI and use the JQuery Each function to save the order using an AJAX request to a basic PHP file. The requests seem to be fine (Firebug console) but not every one is being saved by the PHP file, worse of all it doesn’t seem to be consistent, some id’s are more likely to fail but this seems to be related to their position in the list! It’s really strange, any ideas?

I have tried GET/POST, sync/async, made no difference.

Javascript

function SaveChanges() {
        priority = 0;
        $("#p_menu li").each(function() {
           if($(this).attr("class") != "range") {
               $.ajax({"url": "lib/product-menu-save.php", "data": "pm_id="+this.id+"&priority="+priority, "type": "GET"});
               priority++;
           }
        });
    }

PHP file

<?php

require_once '../includes/adminsession.php';
require_once '../lib/mysql.php';

$pm_id = $_GET['pm_id'];
$pm_priority = str_pad($_GET['priority'], 4, '0', STR_PAD_LEFT);

$save_stmt = $db->prepare("UPDATE products SET priority = ? WHERE id = ?");
$save_stmt->bind_param('si', $pm_priority, $pm_id);
if(!$save_stmt->execute()) echo $save_stmt->error; else echo 'SUCCESS';

The data looks fine going into the AJAX request and SUCCESS is returned for every request. There are around 60 items if that is relevant.

  • 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-30T12:13:51+00:00Added an answer on May 30, 2026 at 12:13 pm

    You could send the ids as a list in order to minimize the AJAX requests to a single one.
    (since you will be sending all ids together you do not need to send the priority.. you can handle that server-side)

    function SaveChanges() {
        var id_list = [];
        $("#p_menu li").each(function() {
           if($(this).attr("class") != "range") {
              id_list.push( this.id );
           }
        });
        $.ajax({
                 url  : 'lib/product-menu-save.php', 
                 data : {ids: id_list}, 
                 type : 'POST'
              });
    }
    

    and (something like this, as i am not proficient in PHP)

    $save_stmt = $db->prepare("UPDATE products SET priority = ? WHERE id = ?");
    
    $pm_priority_value = 0;
    
    foreach ($_POST['ids'] as $pm_id) {
    
       $pm_priority = str_pad($pm_priority_value, 4, '0', STR_PAD_LEFT);
    
       $save_stmt->bind_param('si', $pm_priority, $pm_id);
       if(!$save_stmt->execute()) echo $save_stmt->error; else echo 'SUCCESS';
    
       $pm_priority_value++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello there Iam using Jquery 1.6.2 and JqueryUI 1.8.16 I have a sortable list
I have a list made as sortable using jQuery UI. The first list item
I'm using the sortable function in jquery to sequence a faq list. Needless to
We have a sortable list using JQuery UI Sortable that we are trying to
I have a sortable list of folders using JQuery UI. The thing is that
I have a list on my website. I'm using jQuery's sortable tutorial to give
I have built a sortable list using jQuery UI's sortable feature, this is working
I have a sortable list of divs using the jquery UI. It works fine.
I have a sortable list like this one: http://jqueryui.com/demos/sortable Is it possible to get
I have the following ListView in which I am using the JQuery UI sortable

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.