Reputation: 759
Below is the method where i used toUpperCase() to convert params of my ajax function, but there are lots of function in my project and it is difficult for me to convert each param in uppercase.
How can i use $.ajaxSend global function of jquery to convert each param in to uppercase before it get posted to server.
$.ajax({
url: isProductExistsURL,
dataType: 'json',
type: 'GET',
ContentType: "application/json; charset=utf-8",
data: {
locId: locId.toUpperCase(),
prodId: prodId.toUpperCase(),
suffix: suffix.toUpperCase()
},
success: function (exists) {
if (exists) {
if (showInSummary) {
populateValidationSummaryWithCustomError(msg, 'Product');
}
else {
jAlert(msg, 'Alert', function () {
$(element).val('');
$(element).focus();
});
}
}
},
error: function (data, error, status) {
debugger;
alert("error ");
},
beforeSend: function (settings,jqXHR) {
debugger;
$("input[type=text]").each(function () {
this.value = this.value.toUpperCase();
});
$.blockUI();
},
complete: function () {
$.unblockUI();
}
});
Upvotes: 1
Views: 1224
Reputation: 26143
Okay, this is the last attempt. I hope it's finally what you're looking for.
I've overridden the global ajaxSend
event, as requested and have modified the querystring, setting all values to uppercase. This will not work unless you are using GET, as you are in your example...
$(document).on("ajaxSend", function(event, jqXHR, ajaxOptions) {
var url = ajaxOptions.url;
if (url.search("\\?") == -1) return;
var querystring = url.split("?")[1];
url = url.split("?")[0];
var split = querystring.split("&");
querystring = "";
for (var i = 0; i < split.length; i++) {
var key = split[i].split("=")[0];
var value = split[i].split("=")[1].toUpperCase();
querystring += (querystring == "" ? "?" : "&") +
key + "=" + value;
}
ajaxOptions.url = url + querystring;
});
Here's a working example. Just check the console to see the URL, complete with querystring and uppercase values...
Upvotes: 1