Redirect to index.html in case of an error

Use this board for starting discussions, asking questions, and giving advice on Web programming for the IBM i platform (and predecessors.)
Theju112
Profound User
Posts: 48
Joined: Fri Jul 10, 2020 8:35 am
First Name: Thej
Last Name: Pav
Company Name: Confidential
Phone: 00918310800134
Address 1: Chennai
Address 2: India
City: Chennai
State / Province: Outside Canada/USA
Zip / Postal Code: 673592
Country: India
Contact:

Redirect to index.html in case of an error

Post by Theju112 »

I have a requirement where I need the user to be re-directed to the index.html page of a phone-gap app incase of an error.

Below is the Javascript snippet where this action must be executed.

Code: Select all

// IF NO URL, GO BACK TO INDEX
	        if (url == '""')
            {
            	// leave login screen and load main app screen
				//**PAVT --> Alert user of incorrect credntials.
				  alert("Incorrect user name or password!");
				  
            };
The file containing the above code is placed in the folder app/www/js. The index.html file is placed in the www folder.

So I tried adding the below line:

Code: Select all

window.location.href=pui.normalizeURL("index.html");


But I get a run time error which says "file not found."

I have used another js program as reference which seems to be doing the same thing.

The code in my reference program, also in the JS folder is:

Code: Select all

window.location.href=pui.normalizeURL("DriverMain.html");
where DriverMain.html is also in the www folder and this seems to be working fine.

I have also tried using random things like which also doesnt work..

window.location.href=pui.normalizeURL("http://iesaccess.com:8080/profoundui/us ... _AUTH.json")

Can someone please guide how to achieve this?
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Redirect to index.html in case of an error

Post by Scott Klement »

You definitely don't want to be calling pui.normalizeURL() -- that will put your IBM i location into the URL, and you stated that you want the index.html from within the app, right?

Can you explain what you're trying to accomplish by redirecting to index.html?? This is a very strange thing to do.
Theju112
Profound User
Posts: 48
Joined: Fri Jul 10, 2020 8:35 am
First Name: Thej
Last Name: Pav
Company Name: Confidential
Phone: 00918310800134
Address 1: Chennai
Address 2: India
City: Chennai
State / Province: Outside Canada/USA
Zip / Postal Code: 673592
Country: India
Contact:

Re: Redirect to index.html in case of an error

Post by Theju112 »

In this scenario, the index.html page is the starting point of the app.

Below is from the config.xml.
<content src="index.html" />

This runs a script appLogin.js which renders the sign-in form to the user. The code has been written in such a way that if the user enters a non blank user id and password, user would be re-directed to a new file using the below code:

window.location.href=pui.normalizeURL("DriverMain.html");

And a further validation is done in the script loaded in this page which checks if the user id/password combo is valid.

So, what I am trying to do is, to re-direct the user back to index.html (the sign-in form) if the credentials are incorrect. Hope I am correct.
Last edited by Theju112 on Wed Oct 07, 2020 11:02 am, edited 1 time in total.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Redirect to index.html in case of an error

Post by Scott Klement »

You understand that reloading the index.html will reinitialize everything, killing your profound ui session, and so forth? This is not normally done in a single-page application framework such as Profound UI.

Assuming you started from index.html in the first place, an easy way to reload it would be to do this:

Code: Select all

window.location.reload(true);
Theju112
Profound User
Posts: 48
Joined: Fri Jul 10, 2020 8:35 am
First Name: Thej
Last Name: Pav
Company Name: Confidential
Phone: 00918310800134
Address 1: Chennai
Address 2: India
City: Chennai
State / Province: Outside Canada/USA
Zip / Postal Code: 673592
Country: India
Contact:

Re: Redirect to index.html in case of an error

Post by Theju112 »

In this scenario, the index.html page is the starting point of the app.

Below is from the config.xml.
<content src="index.html" />

This runs a script appLogin.js which renders the sign-in form to the user. The code has been written in such a way that if the user enters a non blank user id and password, user would be re-directed to a new file using the below code:

window.location.href=pui.normalizeURL("DriverMain.html");

And a further validation is done in the script loaded in this page which checks if the user id/password combo is valid.

So, what I am trying to do is, to re-direct the user back to index.html (the sign-in form) if the credentials are incorrect. Hope I make sense.
Theju112
Profound User
Posts: 48
Joined: Fri Jul 10, 2020 8:35 am
First Name: Thej
Last Name: Pav
Company Name: Confidential
Phone: 00918310800134
Address 1: Chennai
Address 2: India
City: Chennai
State / Province: Outside Canada/USA
Zip / Postal Code: 673592
Country: India
Contact:

Re: Redirect to index.html in case of an error

Post by Theju112 »

Scott Klement wrote:You understand that reloading the index.html will reinitialize everything, killing your profound ui session, and so forth? This is not normally done in a single-page application framework such as Profound UI.

Assuming you started from index.html in the first place, an easy way to reload it would be to do this:

Code: Select all

window.location.reload(true);
Hi Scott,

I started from index.html but when this validation occurs, I am in another page, DriverMain.html. I tried using window.location.reload(true); but seems it is reloading the drivermain.html page itself and not going back to index.html
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Redirect to index.html in case of an error

Post by Scott Klement »

So is it as simple as this?

Code: Select all

pui.link("index.html");
Theju112
Profound User
Posts: 48
Joined: Fri Jul 10, 2020 8:35 am
First Name: Thej
Last Name: Pav
Company Name: Confidential
Phone: 00918310800134
Address 1: Chennai
Address 2: India
City: Chennai
State / Province: Outside Canada/USA
Zip / Postal Code: 673592
Country: India
Contact:

Re: Redirect to index.html in case of an error

Post by Theju112 »

Works like a gem.. thanks scott!
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests