开发者

Jquery - Send variables to a controller Action via GET in AJAX

开发者 https://www.devze.com 2022-12-16 02:52 出处:网络
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\"];

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"?

开发者_JAVA技巧

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?


data: {itemId: itemId},


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


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

var itemId = {'itemId': 1000};


data: {itemId: "you info"},

or

data: "itemId=you info",
0

精彩评论

暂无评论...
验证码 换一张
取 消