Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX returned data - how to treat them with jQuery
    primarykey
    data
    text
    <p>So when jQuery makes an <code>$.ajax</code> request, the returned data can be handled with the <code>success</code> function attribute (a function) of the object passed as a parameters to <code>$.ajax</code>. As the <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow">API docs</a> report, if the <code>processData</code> attribute is set to <code>true</code>, the data will be returned as a string, otherwise as a DOM object (is that right?).</p> <p>So, I need to treat the data as if they were simple HTML. Let's say I have to prepend and append a series of <code>=</code>s to every <code>h1</code> tag in the returned data, and then fill a page with those data as if they were a plain string (in order to use the jQuery <code>.html()</code> method).</p> <p>What's the correct way to do it?</p> <p>I found that the <code>.parseHTML()</code> jQuery function could be useful in order to parse the returned data string into HTML DOM. But how do I treat it?</p> <p>Sorry for some lack of <em>what have you tried</em> in this question.</p> <h3>Edit</h3> <p>Someone suggested a more clear example. I have a <code>.html</code> file with some content I want to retrieve through AJAX and use to fill my main page content. This file is structured as simple HTML, without <code>head</code>/<code>body</code> tags, just some <code>p</code>s and a few <code>h1</code>s. Through CSS I already made <code>h1</code> tags look exactly like <code>p</code>s (which is intended). Now I want to transform this:</p> <pre><code>&lt;h1&gt;I'm a simple header&lt;/h1&gt; </code></pre> <p>into plain text this:</p> <pre><code>=================== I'm a simple header =================== </code></pre> <p>kind of Unix terminal style.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload