Does jQuery remove script tags returned by AJAX requests?
I'm performing an 开发者_如何学CAJAX call in my jQuery-based JavaScript code. The response contains a <script>
tag. However, it seems jQuery removes this tag.
Is this normal behavior of jQuery or XHR or a bug?
It will depend on the dataType
option you set in your AJAX call. If you set it to html
it will give you back the HTML as plain text with the script tags ready for insertion to the DOM. If it is set to script
then jQuery will attempt to run the script and return the result as a plain text string.
If you are not setting a dataType
then jQuery will automatically infer the type from the response MIME type.
Have a look at the jQuery docs ( http://api.jquery.com/jQuery.ajax/ ) for more info on the dataType
setting.
Depends on your jQuery version.
I've tried 1.4 and will remove (but execute) <script>
while 1.9 will keep it.
精彩评论