I'm performing an AJAX 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With