'optimize ajax code and don't repeat myself
This is my code I don't want repeat my ajax how can I optimize it ? and then have shorter code? so i show you just an example here:
function for() {
if (forceexs) {
if (login == "inte") {
$.ajax({
url: "index_content.php?mode=ppanel=forgotten&force_mssante=0",
success: function (html) {
$(".panel-body").html(i18n.tr(html));
$("#rpps").focus();
},
});
} else if (login == "ex") {
$.ajax({
url: "index.php?mode=nel=forgorce_mssante=1",
success: function (html) {
$(".panel-body").html(i18n.tr(html));
$("#rpps").focus();
},
});
} else {
$.ajax({
url: "index.php?mode=phel=internal_or_external",
success: function (html) {
$(".panel-body").html(i18n.tr(html));
$("#rpps").focus();
},
});
}
} else {
$.ajax({
url: "index.php?mode=pel=forgotten",
success: function (html) {
$(".panel-body").html(i18n.tr(html));
$("#rpps").focus();
},
});
}
}
This is the shortest one more easy to understand
Solution 1:[1]
function ajaxRequest(GETQuery) {
$.ajax({
url:'index_content?'+GETQuery,
success: function(html) {
$(".panel-body").html(i18n.tr(html));
$("#rpps").focus();}
})
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tom |
