tags:

views:

100

answers:

4

All,

I want to send a variable "itemId" via GET to a controller action through AJAX. In the Controller Action, I should be able to retrieve the value using $_GET["itemId"];

Can I send the querystring with "data" tag instead of appending it to the "url"?

I have the following code:

  $.ajax({
          type: 'GET',
          url: "/controller/controlleraction",
          data:  itemId,
          cache: false,
          dataType: "html",
          success: function(html_input)
            {
              alert(html_input);
            }
        });

How can I do this?

A: 

Make itemId a JavaScript object before making the AJAX request. For example:

var itemId = {'itemId': 1000};
CalebD
A: 
data: {itemId: "you info"},

or

data: "itemId=you info",
andres descalzo
+1  A: 

data: {itemId: itemId},

Balon
A: 
$.ajax({
      type: 'GET',
      url: "/controller/controlleraction",
      data: ({itemId: itemId}),<------change it to this
      cache: false,
      dataType: "html",
      success: function(html_input)
        {
          alert(html_input);
        }
    });
Patricia