Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send dynamic key and value both in jQuery Ajax? [duplicate]

I want to send both the key and value to be dynamic(and the key is dynamic like coming from user input). Then how to send the request. I want something like this:

var requestString;

if(something)
   requestString = "something";
else
   requestString= "else";

    jQuery.ajax({
                        url: handlerUrl,
                        dataType: "json",
                        data: {
                            requestString: request.term
                        }
                    });

Here requestString is a variable and dynamically set. But for current code. the key is itself becoming "requestString" which was ought to be dynamic. How to do this?

like image 951
soham Avatar asked Apr 26 '13 09:04

soham


1 Answers

Use

jQuery.ajax({
           url: handlerUrl,
           dataType: "json",
           data: requestString + '=' + request.term
      });
like image 119
Arun P Johny Avatar answered Oct 17 '22 23:10

Arun P Johny