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 },
        });
8
  • 1
    Assuming it's a string, data: data will do it Commented Jan 20, 2017 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 Commented Jan 20, 2017 at 17:25
  • Exactly, that's what you asked for...? Commented Jan 20, 2017 at 17:25
  • If you're trying to build an object, split by ',', replace = with : (better yet, do that in reverse). Commented Jan 20, 2017 at 17:25
  • take a look at here stackoverflow.com/questions/11557526/… Commented Jan 20, 2017 at 17:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.