0
Hello, I am looking for methods to solve a problem I have, as it is a more internal problem, I can not divulge much information but I will exemplify here with some blocks of code.
THE PROBLEM:
I have the following situation:
I have a link on a page (www.site.com) that when clicked, opens a new page of my site (www.site.com/page-1) and when the page finishes loading it already opens a modal who makes a request Ajax
seeking information from database.
This link opens the URL with a parameter that calls this modal (www.site.com/page-1? modal=open).
Note: When talking about Modal, consider basic modal of Bootstrap, okay?
Right? Are you still following? Haha. When this modal is closed (Modal close button) the parameters are still there in the right URL? That’s common, okay? My problem starts right at this point. I have another feature outside this modal, and it’s conflicting with the URL parameters. Read below:
In addition to the modal that makes request Ajax
, I have also Flap navs (Those that you click and change the contents of the tab) that load on each one, a text via Ajax
.
This behavior of changing the Tab is done through the Javascript
and uses the attribute ID
of HTML
to reference, right?
It turns out that when the ABA is clicked to call the tab with the content, in theory, it is adding the #aba1 (which is the tab ID) at the end of my current url with the parameters, and so the tab is exchanged but the request Ajax
is not made and returns null
(I mean, nothing returns, goes blank). See below:
www.site.com/page-1? modal=open#aba1
[Website] www.site.com
[Page name] /page-1
[Parametros of the Modal] ?modal=open
[ID of Aba] #aba1
Did you understand? There is no way I can make a code simulating the error. But the information above makes the problem well explained. I hope I’ve been clear, but just focus on each point I said that is easy to understand the problem.
Another curious thing, to take into account if someone is going to take the time to help me with a solution, haha: If the URL parameter is valid and returns something to the page, the tabs Don’t Work, however if it is any unused parameter that does not return or do anything, the tabs work correctly. These are the points.
What I would need from the community is insights interesting so I can try to implement:
- Be tips for manipulations
- Be examples of codes
- Explanations of logic to solve
- Etc.
My only idea would be to close the modal a JS script captures the current URL and remove everything after the ?. The point is that today there are 3 standard ways to close the modal: Through the Close button, through a button on the modal body (Close) or click outside the modal area. So I don’t know if this idea would work.
Well, that’s it. For those of you who can help me, I’ll be here to supplement the questions if there are any questions.
Thanks to all of the community.
P.S.: Development Stack: Ruby, R'Rails, Javascript.
It does not seem to me to be so complex what you need, and it seems to me that in your question already exists the answer, you need methods to manipulate the
urls
... But without code it is difficult to know for example how to work with invalid parameters and not with valid ones. There are a number of methods to manipulateurls
, which will suit you need to be clear how the thing is... Theoretically it’s all clear, but in practice the theory is different...– MagicHat
@Magichat I’ll see if I can exemplify with code..
– Lougans de Matos
@Magichat appears but does not solve... What I’m using is history.pushState() but it just changes the URL, I can’t make the ajax request I need.. I will add that to the question..
– Lougans de Matos
Come on, your code would not "simulate the error", it is necessary, to have a context of something that can be reproduced, debugged and fixed. That being said, your question becomes ample, and without sufficient resources for there to be an objective answer. You know how it works, theoretically the fault is clear, "manipulate the url", however the problem itself seems to happen in the request you are making, where invalid parameters are passed (modal=open), and you have the other part where you say it works with invalid parameters...
– MagicHat
@Magichat, a valid parameter is the
?modal=open
because it returns the modal opening on the screen. Invalid is if I add anything after the "?".– Lougans de Matos
Let’s simulate a String that has the entire site: www.site.com/page-1? modal=Ope#aba1 (var string) var site = string.split("/")[0]; var pagina = string.split("/")[1]. split("?")[0]; var parametro = string.split("?")[1]. split("#")[0]; var aba = string.split("#")[1] the rest you do yourself, I hope I’ve helped
– Walter Felipe