Inserting HTML code with jquery

Posted by J. Robertson on Programmers See other posts from Programmers or by J. Robertson
Published on 2013-08-16T20:21:33Z Indexed on 2013/10/31 10:19 UTC
Read the original article Hit count: 335

Filed under:
|
|

One of our web applications is a page that takes in a serial number and various information is returned and displayed to the user. The serial is passed via AJAX, and based on the response, one of the following can happen -

  • An error message is shown
  • A new form replaces the previous form

Now, the way I am handling this is to use jQuery to destroy (using $.remove()) the table that displayed the initial serial form, then I'm appending another html table that contains another form. Right now I am including that additional form as part of the html source, and just setting it to display:none, then using jQuery to show it when appropriate. However, I don't like this approach because if someone views source on the page, they can see that table html code that is not being displayed.

My next thought would be to use AJAX to read in another HTML file, and append it that way. However, I am trying to keep down the number of files this project uses, and since most pages in our project will use AJAX, I could see a case where there are multiple files containing HTML snippets - and that feels sloppy to me.

What is the best way to handle a case where multiple html elements are being shown and removed with jQuery?

© Programmers or respective owner

Related posts about php

Related posts about jQuery