Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a query string with JQuery

Tags:

jquery

I have the following code that builds a query string:

    var name = $(this).next()[0].name;
    var value = $(this).next()[0].checked;
    var str = name+'&value='+value;

and outputs an array on my server like this:

[value] => false

What I would like to have is something more like this:

array(
    [myInputName] => value
)

How can I achieve this?

like image 277
NaN Avatar asked Dec 04 '25 14:12

NaN


1 Answers

Just use

var str = name + '=' + value;

What you have would output something like:

myInputName&value=myInputValue

Using name in that way is not useful.

like image 71
Explosion Pills Avatar answered Dec 07 '25 02:12

Explosion Pills



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!