Jump to content

Complex HTML as a string in JS?


DWilliams

Recommended Posts

There's about 3 or 4 different forums I could post this in, but I guess I'll pick this one.

 

Long story short I have an AJAX call that returns some code to be eval'd. In this case, it needs to update the report container div on my page with the results of the AJAX call.

 

I'm not very experienced with JavaScript but this should be a simple enough task. When I set my AJAX function up to return

document.getElementById('reportarea').innerHTML = 'test';

Then it works just fine. If I replace "test" with my report's HTML, nothing happens (presumably JS is erroring out on it). Now, I just figured this was a case of not escaping quotes or something, but I ran my report HTML through addslashes() and the same thing happens.

 

The HTML the AJAX function returns is unpredictable and can contain all sorts of wonky stuff like linebreaks, semicolons, quotes, brackets, and whatever else. Currently this is a sample of what it's trying to return that does not work:

 

document.getElementById('reportarea').innerHTML = '<b>Client:</b>CLIENTNAME<br />
<b>Date Range:</b> <br /><br />

<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\">
<tr>
<th>Listed</th><th>Acct #</th><th>Name</th></tr>
<tr>
<td>11/16/2009</td><td>AE1000</td><td>JOHN DOE</td><td>1600.00</td></tr>
<tr>
<td>11/16/2009</td><td>AE1000</td><td>JOHN DOE</td><td>1600.00</td><td>11/16/2009</td><td>AE 1001</td><td>JANE DOE</td><td>700.00</td></tr>
</table>
<br /><br />
<b>Number of Accounts:</b> 2<br />
<b>Total Placement Amount:</b> 2300<br /><br />
<b>NOTE: Interest, if assigned, will accrue on the above account(s).
<br />
Thank you for choosing OURCOMPANY for your collection needs!</b>

';

 

What do I actually need to do to prepare this HTML to be acceptable to JavaScript?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.