How to post javascript as text with jQuery.ajax

GIgaSharez

New Member
I have a form that asks the user to enter their Google Analytics code in a textarea. I then pass this string into ajax post and receive an error saying that I am passing an invalid object. (I am not pasting the whole error message here as it is quite long..)The Google Analytics code, as expected, is in the form of following;\[code\]<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'some_number']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = http://stackoverflow.com/questions/12468759/('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();</script>\[/code\]And I use this to post to server:\[code\] $.ajax({ type: "POST", url: "Settings.aspx/setStats", data: "{'skey': 'ga_code', 'sval':'" + el.val() + "'}", dataType: "json", contentType: "application/json; charset=utf-8" }); // el.val() being the google analytics code..\[/code\]How can I post this without the error? Also, I will need to get it as well, when the user needs to update it.. Will the same problem arise when receiving it too?
 
Back
Top