issues with not reloading the form after the success message only

Gurpreet Singh Randhawa
Gurpreet Singh Randhawa used Ask the Experts™
on
try to reload the page after a success message, but it is not reloading..

i have this code

$.ajax({
				type:"post",
				url: '/action.cfm?method=quote',
				data: datastring,
				success: function(data) {
					var valid = $.trim(data);
					if(valid.toLowerCase().indexOf("error") == '-1') {
						localStorage.setItem("swal",swal({title:"Good job!", text:'Thanks',
						type:"success",showConfirmButton: true}).then(function(){
						location.reload();
						})
						);
						localStorage.getItem("swal");
					}else {
						swal("Oops",data,"error");
					}
				}
			});

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David S.Consultant & Challenge Subduer
Top Expert 2009

Commented:
I've got to ask, why use AJAX if you're going to reload the page after such a request is successful? AJAX is typically used to avoid that.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I am confused by what you are trying to do?

You are passing the return from the call to the sweet alert as the data parameter to the localStorage.setItem - why?

Then as David says you reloading the page - why do you want to reload the page?
i get an error on this

(index):389 Uncaught TypeError: Cannot read property 'then' of undefined
    at Object.success ((index):389)
    at fire (jquery-1.12.4.js:3232)
    at Object.fireWith [as resolveWith] (jquery-1.12.4.js:3362)
    at done (jquery-1.12.4.js:9840)
    at XMLHttpRequest.callback (jquery-1.12.4.js:10311)

Open in new window

Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

after clicking the OK button in swal, i want to reload the page

and i am using sweetalert 2
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
after clicking the OK button in swal, i want to reload the page
Why?
Well because I am using sessions to block user one submit per ip
Hi,

I would add the JS reload page part in the server side code not in the Ajax part
after all server side validation and php code completed
then echo the reload script
Modified to fire he swal.fire to fix the issue

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial