SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Jquery sortable serialize

    Hey guys,
    check out this code below:

    Code:
    	 
    $('#reorder').click(function( event){
    var order = $('#gallery').sortable('serialize',{key:'string'});
    console.log(order);
    				 });
    This gives me a string :
    string=1&string=2&string=3&string=4

    I only want the numbers and I want them as an array to send via AJAX to my server side script to re-order the database. Please advise.

    thanks

    Silversurfer
    "Persistence is the path to perfection"

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    The serialize method in the sortable documentation says that it automatically uses array notation when you don't provide a key.

    It works by default by looking at the id of each item
    in the format 'setname_number', and it spits out a hash like
    "setname[]=number&setname[]=number".
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [SOLVED]
    Ah excellent, thanks Paul,

    I also didn't realize that:

    index[]=2&index[]=1&index[]=3&index[]=4

    is the same as: index[0]=2, index[1]=1, index[2]=3, index[3]=4

    I am used to sending scalar GET and POST variables but this is the first time I have had to send a vector.
    "Persistence is the path to perfection"


Bookmarks

Posting Permissions

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