I'm trying to create a reusable function that will allow me to call an AJAX request and use one of the passed in parameters as an argument in the data section of the AJAX call.
// Returns AJAX data for updating other fields based on a dropdown changing
App.prototype.OnDropdownChange = function (s, e, newId, ajaxParameter, ajaxRequestURL) {
// Create an AJAX request based on the parameters
$.ajax({
url: ajaxRequestURL,
data: JSON.stringify({ ajaxParameter: newId }),
type: 'POST',
success: function (data) {
// Return the data
return data;
},
error: function (data) {
// Error
return data;
}
});
}
The "ajaxParameter" would, ideally, hold the name of the parameter being passed up. So for example, "ajaxParamter" contains "theNewID" which is what my MVC controller is expecting as a parameter however when it's passed up it is shown as "ajaxParameter" and not the value inside.
How can I get this working?
EDIT
https://i.stack.imgur.com/ocJBi.jpg
See here how it shows as ajaxParameter? What I want is that to be whatever I pass it in as.