Reputation: 7468
Ok,
I have a some javascript code in the database
Table: jsSnippets
Field: snippet
Type: Text
<SCRIPT SRC="https://svc.com/somestuff.js"></SCRIPT>
<script>
var fubar = 'stuf'
send_some_stuf_to_svc(fubar) // sends some data to a service :)
</script>
So i have N number of this JS snippets
will that code work if a server side method was called via Ajax call, for example:
$.ajax({
type: 'GET',
url: path + '/doTheJSStuff/',
)};
where the doTheJSStuff is a method that echo/prints the JS code
Upvotes: 0
Views: 77
Reputation: 8582
That will work, so long as the contents of the <script>
tag are being passed into javascript's eval() function. If you're using a framework such as jQuery, its built-in $.ajax() method eval's tags automatically.
Upvotes: 1
Reputation: 40512
eval(text)
after receiving text.Upvotes: 3