[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Eric Pascarello wrote:How are you adding this fragment to the page?
Eric
Eric Pascarello wrote:WHAT is your JavaScript that adds the html to the page. Actual code, not words.
Eric
Art Vandelay wrote:Let's say I have a jsp page from which I make an AJAX call to another jsp page that renders to say a form tag, that i add to a div tag using javascript.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sagar Rohankar wrote:
Art Vandelay wrote:Let's say I have a jsp page from which I make an AJAX call to another jsp page that renders to say a form tag, that i add to a div tag using javascript.
Why do you have an AJAX call just to include another JSP page. Can't you used ?
Art Vandelay wrote:
Sagar Rohankar wrote:
Art Vandelay wrote:Let's say I have a jsp page from which I make an AJAX call to another jsp page that renders to say a form tag, that i add to a div tag using javascript.
Why do you have an AJAX call just to include another JSP page. Can't you used ?
because it needs to go through a controller at the backend that does some processing and contains some business logic.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sagar Rohankar wrote:
Art Vandelay wrote:
Sagar Rohankar wrote:
Art Vandelay wrote:Let's say I have a jsp page from which I make an AJAX call to another jsp page that renders to say a form tag, that i add to a div tag using javascript.
Why do you have an AJAX call just to include another JSP page. Can't you used ?
because it needs to go through a controller at the backend that does some processing and contains some business logic.
But "form.htm" is just a static page. Which business logic it contains ?
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sagar Rohankar wrote:Whats the output of 'form.htm'. Try making a simple request to the server, like http://localhost:8080/yourapp/form.htm & and append the <link../> tag to the form.htm output itself. See whether it get displayed correctly or not on browser.
Sagar Rohankar wrote:.. and append the <link../> tag to the form.htm output itself. See whether it get displayed correctly or not on browser.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sagar Rohankar wrote:Also, for my sake of interest, try out this page.
Sagar Rohankar wrote:
Sagar Rohankar wrote:.. and append the <link../> tag to the form.htm output itself. See whether it get displayed correctly or not on browser.
Try.
Art Vandelay wrote:
Sagar Rohankar wrote:Also, for my sake of interest, try out this page.
This will not leas to anything, because the page fragment to include is not fixed but determined dynamically; user selects from menu bar and action that the would like to perform and based on this selection a request is made to generate the according html fragment to add to the page.
i tried adding the <link style....> tag, and is does work, thanks!!!
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sagar Rohankar wrote:
Art Vandelay wrote:
Sagar Rohankar wrote:Also, for my sake of interest, try out this page.
This will not leas to anything, because the page fragment to include is not fixed but determined dynamically; user selects from menu bar and action that the would like to perform and based on this selection a request is made to generate the according html fragment to add to the page.
But, my question is, have you tried this?
If it works, then we can hide that FORM part which we included, and visible it if user wished to see that FORM.
i tried adding the <link style....> tag, and is does work, thanks!!!
But it comes with one con, it just duplicates the CSS in the main page. Have a separate css file for FROM element and append it.
Finally, I still didn't get it, why AJAX call doesn't updates the FROM with the existing page CSS
Art Vandelay wrote:btw. i run into another issue; i submit the form using an AJAX call and the form will be validated at the backend, but if there are validation errors, the response will be the submitted form with validation error messages, in this case i want a callback function to receive this response and display that form, overwriting the submitted one. But is there are no validation errors, the response will be a new page, which of course must lead to a new page being displayed (user is forwarded to a new page). Is there some kind of approach/mechanism/etc that you know of that can help to build this logic using AJAX?
Bear Bibeault wrote:
Art Vandelay wrote:btw. i run into another issue; i submit the form using an AJAX call and the form will be validated at the backend, but if there are validation errors, the response will be the submitted form with validation error messages, in this case i want a callback function to receive this response and display that form, overwriting the submitted one. But is there are no validation errors, the response will be a new page, which of course must lead to a new page being displayed (user is forwarded to a new page). Is there some kind of approach/mechanism/etc that you know of that can help to build this logic using AJAX?
That made my hair fall out.
You can't have it both ways. You can use Ajax to get a fragment or data back, or use a full-page refresh. They can;t be mixed in one response.
What I generally do is to submit the form using Ajax. A list of errors is returned in JSON format. If the list is empty all is good and I go on to whatever's next (closing dialog, redirecting to a new page, whatever). If there are errors, I display them and mark the field invalid (assign a class that identifies them as invalid and modifies their appearance). Fewer moving parts means fewer opportunities for errors and problems.
Why do you feel that you need to replace the whole form when a perfectly good one is already there?
Art Vandelay wrote:Someone any idea how to look for a certain element by id in another element
how to replace the entire contents of a page (document)?
Bear Bibeault wrote:
Art Vandelay wrote:Someone any idea how to look for a certain element by id in another element
Since an id must be unique within a page, any idea of containment is moot. Simply search for an element with the id.
how to replace the entire contents of a page (document)?
Art Vandelay wrote:data.getElementById('myForm') does unfortunately not work.
but i already have the contents of the new page i just have to assign them to the current page.
Bear Bibeault wrote:
Art Vandelay wrote:data.getElementById('myForm') does unfortunately not work.
At this point, data is just a string and String doesn't have a getElementbyId method.
but i already have the contents of the new page i just have to assign them to the current page.
And again, sending a whole new page as an Ajax response doesn't make any sense. You can't do anything with it. You either need a fragment you can stick into the current DOM, or redirect to a new page. You can't replace the page in-place.
In my opinion, you are trying to do way too much on the client. These are all the types of things that should be handled on the server. If your choice of server-side tools is making your job harder rather than easier, perhaps it's time to re-evaluate those tools or the manner in which you are using them.
The answer to "I'm not getting back what I want (need) as the Ajax response" is always "fix the server code".
Bear Bibeault wrote:I'm not going to argue with you -- that's not what I'm here for. I'm here to offer help. If you say that the response is correct, then it's correct.
But I will offer this bit of closing food for thought: if you don't know how to deal with a response on the client, is it really correct? And, is it worth keeping things simple on the server at the expense of great complexity on the client? Just some things to ponder over your dessert.
Bear Bibeault wrote:Client-side validation is never sufficient on its own.
Surely, your framework is versatile enough such that you can choose what is returned and what is not?
(Not to go off on a side rant, but this is the reason I eschew big frameworks. You frequently do it their way, or no way at all.)
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sagar Rohankar wrote:... and BTW do you have any hair left to fall out
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|