0

I have

var data = decodeURIComponent($(this).attr("name"));

output of var data is

ldef_index[]=5&lquality[]=0&id[]=&rdef_index[]=315&rquality[]=0&rdef_index[]=7115&rquality[]=0&rdef_index[]=50&rquality[]=0&rdef_index[]=55&rquality[]=0&rdef_index[]=5086&rquality[]=0&rdef_index[]=711&rquality[]=0&rdef_index[]=3229&rquality[]=0&rdef_index[]=7555&rquality[]=0&tslt=c9942&notes=test

How can i convert this variable to send it as data in jquery ajax request ?

  $.ajax({
        type : "POST",
        url : 'https://example.com/ajax/test.php',
        data: { ldef_index[]: 5,
                lquality[]: 0,
                id[]= ,
                rdef_index[]: 315,
                rquality[]: 0,
                rdef_index[]: 7115,
                rquality[]: 0,
                rdef_index[]: 50,
                rquality[]: 0,
                rdef_index[]: 55,
                rquality[]: 0,
                rdef_index[]: 5086,
                rquality[]: 0,
                rdef_index[]: 711,
                rquality[]: 0,
                rdef_index[]: 3229,
                rquality[]: 0,
                rdef_index[]: 7555,
                rquality[]: 0,
                tslt: c9942,
                notes: test },
        });
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
MHB2011
  • 453
  • 1
  • 7
  • 22
  • 1
    Assuming it's a string, `data: data` will do it – Rory McCrossan Jan 20 '17 at 17:24
  • @RoryMcCrossan already tryed but it post it as data : ldef_index[]=5&lquality[]=0&id[]=&rdef_index[]=315&rquality[]=0&rdef_index[]=7115&rquality[]=0&rdef_index[]=50&rquality[]=0&rdef_index[]=55&rquality[]=0&rdef_index[]=5086&rquality[]=0&rdef_index[]=711&rquality[]=0&rdef_index[]=3229&rquality[]=0&rdef_index[]=7555&rquality[]=0&tslt=c9942&notes=test – MHB2011 Jan 20 '17 at 17:25
  • Exactly, that's what you asked for...? – Rory McCrossan Jan 20 '17 at 17:25
  • If you're trying to build an object, split by ',', replace = with : (better yet, do that in reverse). – Andrew Ice Jan 20 '17 at 17:25
  • take a look at here http://stackoverflow.com/questions/11557526/deserialize-query-string-to-json-object – burkay Jan 20 '17 at 17:29
  • @RoryMcCrossan I want parameters to look like this http://prntscr.com/dy5pzq , and when i send it as data: data it looks like this : http://prntscr.com/dy5rr2 . – MHB2011 Jan 20 '17 at 17:31
  • what does `$(this).attr("name")` return ? – Nikhilesh Shivarathri Jan 20 '17 at 17:44
  • @RoryMcCrossan Actually u were right , i was just sending it in wrong format . Sorry This is solved now. If i send data: data it do just what i want – MHB2011 Jan 20 '17 at 17:49

0 Answers0