How can I pass more parameters with AJAX
I have the following:
$('#TopicDescription').change(function () {
$.ajax({
url: "/adminQuestions/GetSubTopics",
data: $('#TopicDescription').val(),
success: function (data) {
$('#SubTopicDescription').html(data);
}
});
});
This works good but I would like to pass another parameter. Can someone explain how I can do this. Also in the GetSubTopics method will the parameter passed be referenced by the word "d开发者_StackOverflow中文版ata" and is there a connection between data: and the .html(data).
Sorry if my question is confusing.
Beverly
pass an object in data:
data: {
foo : 10,
bar : 42
}
$.ajax({
url: "/adminQuestions/GetSubTopics",
data: { v1: $('#element1').val(),
v2: $('#element2').val(),
v3: $('#element3').val()
},
success: function(msg) {
// do something with msg
}
});
Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).
I hope this helps.
Hristo
精彩评论