Jquery - Send variables to a controller Action via GET in AJAX
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",
精彩评论