How can I get the source code of a .js script within JavaScript?

$.ajax({url: '', dataType: 'script text text', crossdomain:'true', success: function(msg, status, obj){console.log(msg);console.log(status);console.log(obj)}, mimetype: 'text/plain', cache:false}); I have tried running the above code and variants of it - removing mimetype, cache, setting dataType to 'script text' and 'script script text'. Straight from the jQuery Docs: > multiple, space-separated values: As > of jQuery 1.5, jQuery can convert a > dataType from what it received in the > Content-Type header to what you > require. For example, if you want a > text response to be treated as XML, > use "text xml" for the dataType. You > can also make a JSONP request, have it > received as text, and interpreted by > jQuery as XML: "jsonp text xml." > Similarly, a shorthand string such as > "jsonp xml" will first attempt to > convert from jsonp to xml, and, > failing that, convert from jsonp to > text, and then from text to xml I am limited to making the dataType request of type 'script', or else I get a " not allowed by Access-Control-Allow-Origin" error. But by all rights, shouldn't I be free to interpret it within jQuery however I want to? I've clearly requested it as text, yet msg - the returned data from the server - is always 'undefined' regardless of what I do. Are there any workarounds for this, hacky or not? EDIT: This code **works** in that it loads the JavaScript file and downloads it to the user's browser. But I still can't view it!

以上就是How can I get the source code of a .js script within JavaScript?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准