Conditional redirection with the browser component ignoring some conditions

I may be missing something obvious but i have a problem with browser redirects i cant seem to resolve. Before delving into custom php to solve this I thought I would ask here

I know is is simple to redirect conditionally with an expression like browser1.goto( [condition]?’‘page1.html’:‘page2.html’) within the success event.

In my case the server action returns a status code between 0 and 4

what i need is to ignore status codes 0-2 (i.e no redirect) but redirect to “page3.html” and ‘page4.html’ on status codes 3 or 4.

I am running out of ideas, everything i have tried either causes an error or redirects incorrectly

Anyone any ideas?

Hi Brian,
Please try:

browser1.goto( status == 3 ? 'page3.html' : status == 4 ? 'page4.html' : false)

Not sure about the ‘false’ part as I am on my phone currently.

Interesting. needed “F” of false capitalised i.e. “False” but it does work thanks

It does however leave an error in the developers console when the “False” is called i.e. stutus’ 0 - 2

image

Ok, sorry what if you try '' instead of 'false'
I will be able to check this but later, when I am on a computer.

That was my first idea, unfortunately that redirects to the website root

Maybe just change the condition logic, like:

status == 3 ? browser1.goto('page3.html') : status == 4 ? browser1.goto('page4.html') : false

Thanks Teodor, that has done it!

2 Likes

Hello I am having an issue with that. Trying to implement it like this.

<dmx-serverconnect id="check_service" url="dmxConnect/api/surveys/2020/compare.aspx" dmx-param:sid="query.id" dmx-on:success="status==271 ? browser1.goto('https://www.mysite.com') : false"></dmx-serverconnect>

But this won’t execute because I think I am setting the status to 271 and the success (200 status) would trigger the conditional.

So what are you trying to do, Niko?

If the query does not return anything I am setting status==271. This works fine.

I just can’t get it to trigger the browser redirection

If the status is 271 - then your condition should work. Can you please provide a link where i can check this?

Its local… let me check if I am missing something else

Please check your browser console first. Probably some include is missing.

This is what it gets returned regarding status

Please check the console for errors/warnings Niko …

Yes I did… let me recheck

The only warnings that I get in the console is

DevTools failed to parse SourceMap: http://localhost/bootstrap/4/js/popper.min.js.map
DevTools failed to parse SourceMap: http://localhost/bootstrap/4/js/bootstrap.min.js.map
DevTools failed to parse SourceMap: http://localhost/bootstrap/4/css/bootstrap.min.css.map
DevTools failed to parse SourceMap: http://localhost/bootstrap/4/js/popper.min.js.map

These are not related.
I need a link to your page where i can test this.

Yes don’t worry Teo. Just needed to confirm that the condition should be working. I will figure it out. Thank you!!!

Hm, i notice your redirect is added onsuccess event … onsuccess means status 200.

Change it to ondone.

1 Like