Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return AJAX HTML Response Without CSS/JS Interference

Tags:

html

jquery

ajax

I have an AJAX call to a server that will return an HTML response. This HTML response will include HTML, CSS, and JS. I would like to embed this response on my current page so the user will be able to view the response. I have tried the following, but the CSS from the response is applied to my current page. Is there any way to prevent the CSS from being applied to my current page?

Note that I have no control over the CSS returned by the server. The server can return CSS that targets all element types p { color:red } :(

$.ajax ({
    type: TYPE,
    contentType: CONTENT_TYPE,
    url: URL,
    headers: {
        firstName: firstName,
        lastName: lastName
    }
})
.done( function(msg) {
    $('#response').html(msg);
})

<div id="response"></div>
like image 533
Jon Avatar asked Aug 23 '26 00:08

Jon


1 Answers

Better use of CSS selectors would help. Perhaps wrap the result within a container div and add a class to that. Then your css can be used to only target elements within that div.

like image 106
Cjmarkham Avatar answered Aug 24 '26 14:08

Cjmarkham