location.reload
already refresh you page so, the last line in your success callback is not executed anymore (or at least it has no effect on the reloaded page). So no modal will be shown after reload
What you could do to archive your goal is refreshing the page with a special parameter and check for that parameter when the page is loading (and then show the modal)
So instead of location.reload()
do something like (Edited):
window.location.search = updateQueryStringParameter(window.location.search,"success","true")
On the page itself (on load) do something like (Edited):
$(document).ready(function() {
if(getParameterByName("success",window.location.href) == "true"){
$("#successModal").modal('show');
}
});
So the reloaded page will now contain an additional url-parameter and the page itself checks for that and opens the success modal when the param is present
Edit:
The code is now working with all urls (also if there are already url parameters), therefor you also need to add two javascript-helper functions:
//https://stackoverflow.com/a/6021027/1578780
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
}
//https://stackoverflow.com/a/901144/1578780
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}