如果您想了解javascript–jQueryAJAXJSONP错误“意外的令牌”的相关知识,那么本文是一篇不可错过的文章,我们将为您提供关于.tsxwebpack编译失败:意外的令牌的有价值的信息。
如果您想了解javascript – jQuery AJAX JSONP错误“意外的令牌”的相关知识,那么本文是一篇不可错过的文章,我们将为您提供关于.tsx webpack编译失败:意外的令牌<、Ajax 和 XML: 将 Ajax 用于聊天-使用 Ajax 和 PHP 创建聊天应用程序、Ajax.BeginForm()没有工作MVC – 未捕获的javascript错误 – 意外的令牌(、Angular App中的语法错误:意外的令牌<的有价值的信息。
本文目录一览:- javascript – jQuery AJAX JSONP错误“意外的令牌”
- .tsx webpack编译失败:意外的令牌<
- Ajax 和 XML: 将 Ajax 用于聊天-使用 Ajax 和 PHP 创建聊天应用程序
- Ajax.BeginForm()没有工作MVC – 未捕获的javascript错误 – 意外的令牌(
- Angular App中的语法错误:意外的令牌<
javascript – jQuery AJAX JSONP错误“意外的令牌”
我正在尝试在Chrome中进行跨域JSONP调用,但我不断回复“Uncaught SyntaxError:Unexpected token:”
我试过:更改响应内容类型,设置xhr标头,JSON.stringify,这里提供的大多数解决方案,但到目前为止没有任何工作:-(
$.ajax({
type: "POST",
url: "https://www.virustotal.com/vtapi/v2/url/report",
crossDomain: true,
contentType: "application/json; charset=UTF-8",
dataType: ''jsonp'',
data: {
apikey: "*",
resource: "http://www.1001freefonts.com/font/BaroqueScript.zip"
},
jsonp: false,
jsonpCallback: receive,
success: function (data, textStatus, jqXHR) {
console.log("Data retrieved: " + data);
}
}).done(function () {
console.log(''I think we are done here'');
})
.error(function (e) {
console.log(arguments);
console.log(''something went funny here'');
})
.complete(function (xhr, status) {
console.log("complete");
if (status === ''error'' || !xhr.responseText) {
console.log(''error'');
}
else {
console.log("data found:" + xhr.responseText);
//...
}
});
});
function receive(saveData) {
if (saveData == null) {
console.log("DATA IS UNDEFINED!"); // displays every time
}
console.log("Success is " + saveData); // ''Success is undefined''
}
在调试器中,我可以看到响应
{"permalink": "https://www.virustotal.com/url/b5b546fdbb49a2258e951c5e568a52655c65ac56112e39d15af0954a53b36772/analysis/1360339512/", "url": "http://www.1001freefonts.com/font/BaroqueScript.zip", "response_code": 1, "scan_date": "2013-02-08 16:05:12", "scan_id": "b5b546fdbb49a2258e951c5e568a52655c65ac56112e39d15af0954a53b36772-1360339512", "verbose_msg": "Scan finished, scan information embedded in this object", "filescan_id": "b7e13c0242e9690aba1f3da4b73d9c2e99a9b7fd03f542b55e694a34aaf9eca8-1360339519", "positives": 0, "total": 35, "scans": {"CLEAN MX": {"detected": false, "result": "clean site"}, "MalwarePatrol": {"detected": false, "result": "clean site"}, "ZDB Zeus": {"detected": false, "result": "clean site"}, "K7AntiVirus": {"detected": false, "result": "clean site"}, "Quttera": {"detected": false, "result": "clean site"}, "Yandex Safebrowsing": {"detected": false, "result": "clean site"}, "MalwareDomainList": {"detected": false, "result": "clean site"}, "ZeusTracker": {"detected": false, "result": "clean site"}, "zvelo": {"detected": false, "result": "clean site"}, "Google Safebrowsing": {"detected": false, "result": "clean site"}, "BitDefender": {"detected": false, "result": "clean site"}, "Opera": {"detected": false, "result": "clean site"}, "G-Data": {"detected": false, "result": "clean site"}, "C-SIRT": {"detected": false, "result": "clean site"}, "Sucuri SiteCheck": {"detected": false, "result": "clean site"}, "VX Vault": {"detected": false, "result": "clean site"}, "ADMINUSLabs": {"detected": false, "result": "clean site"}, "SCUMWARE.org": {"detected": false, "result": "clean site"}, "Dr.Web": {"detected": false, "result": "clean site"}, "AlienVault": {"detected": false, "result": "clean site"}, "Malc0de Database": {"detected": false, "result": "clean site"}, "SpyEyeTracker": {"detected": false, "result": "clean site"}, "Phishtank": {"detected": false, "result": "clean site"}, "Avira": {"detected": false, "result": "clean site"}, "Antiy-AVL": {"detected": false, "result": "clean site"}, "Comodo Site Inspector": {"detected": false, "result": "clean site"}, "Malekal": {"detected": false, "result": "clean site"}, "ESET": {"detected": false, "result": "clean site"}, "SecureBrain": {"detected": false, "result": "unrated site"}, "Netcraft": {"detected": false, "result": "clean site"}, "ParetoLogic": {"detected": false, "result": "clean site"}, "URLQuery": {"detected": false, "result": "unrated site"}, "Wepawet": {"detected": false, "result": "unrated site"}, "Minotaur": {"detected": false, "result": "clean site"}}}
我在http://jsonlint.com/上验证了它,它表明它是一个有效的JSON.
这是响应标题
cache-control:no-cache
content-encoding:gzip
content-length:695
content-type:application/json
date:Wed, 13 Feb 2013 12:00:33 GMT
server:Google Frontend
status:200 OK
vary:Accept-Encoding
version:HTTP/1.1
任何人有任何想法/建议?
解决方法:
在彻底测试之后,很明显当ajax期望JSONP作为回报时(由于跨域限制),不可能捕获JSON对象结果.即使响应状态= 200.
我一直在测试使用jQuery AJAX调用,试图看看结果是否仍然可以捕获 – 尽管浏览器抛出了解析错误 – 但它似乎不可能.看起来响应文本在JS工作完成后到达标题.
正如@Florian F. @Likwid_T @Christoph上面所建议的那样,一定要使用服务器端脚本才能使其正常工作.其他开发人员似乎热衷于使用C#编写的代理作为解决方案.
.tsx webpack编译失败:意外的令牌<
我的应用程序使用.ts,.js和.jsx文件进行编译并运行。现在,我尝试将.jsx文件更改为.tsx,它会中断。
如何解决此编译错误:
ts-loader: Using typescript@1.6.2 and C:\users\ruser\Desktop\Downloads\divinote\site\tsconfig.json 67% 226/234 build modulesModuleParseError: Module parse failed: C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\ts-loader\index.js?cacheDirectory!C:\users\ruser\Desktop\Downloads\divinote\site\src\app\views\header\DiviAppBar.tsx Line 15: Unexpected token <You may need an appropriate loader to handle this file type.| }| DiviAppBar.prototype.render = function () {| return (<AppBar />);| };| return DiviAppBar; at DependenciesBlock.<anonymous> (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack\lib\NormalModule.js:113:20) at DependenciesBlock.onModuleBuild (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:310:10) at nextLoader (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:275:25) at C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:292:15 at context.callback (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:148:14) at Object.loader (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\ts-loader\index.js:431:5) at WEBPACK_CORE_LOADER_EXECUTION (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:155:71) at runSyncOrAsync (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:155:93) at nextLoader (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:290:3) at C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\webpack-core\lib\NormalModuleMixin.js:259:5 at Storage.finished (C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:38:16) at C:\users\ruser\Desktop\Downloads\divinote\site\node_modules\graceful-fs\graceful-fs.js:76:16 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3) 69% 337/338 build moduleschild_process.js:484
当我编译这段代码时:
"use strict";import React = require(''react'');import AppBar = require(''material-ui/lib/app-bar'');class DiviAppBar extends React.Component{ render() { return ( <AppBar /> ); }}export = DiviAppBar;
与此webpack配置文件:
''use strict'';var webpack = require(''webpack'');var HtmlWebpackPlugin = require(''html-webpack-plugin'');var CopyWebpackPlugin = require(''copy-webpack-plugin'');var path = require(''path'');var rootPath = __dirname; //sitevar srcPath = path.join(rootPath, ''src''); //site/srcmodule.exports ={ bail: true, cache: true, context: rootPath, debug: true, devtool: ''inline-source-map'', //''eval-cheap-module-source-map'',''inline-source-map'' target: ''web'', devServer: { contentBase: ''./dist'', historyApiFallback: true }, entry: { app: path.join(srcPath, ''app/main.jsx''), lib: [''react'', ''react-router''] }, output: { path: path.join(rootPath, ''dist''), publicPath: '''', filename: ''[name].js'', library: [''[name]'', ''[name]''], pathInfo: true }, resolve: { root: srcPath, extensions: ['''', ''.js'', ''.jsx'', ''.ts'', ''.tsx''], modulesDirectories: [''node_modules'', ''src'', ''typings''] }, module: { loaders: [ {test: /\.js$/, loader: ''babel-loader?cacheDirectory'', exclude: /(node_modules|bower_components)/ }, {test: /\.jsx$/, loader: ''babel-loader?cacheDirectory'', exclude: /(node_modules|bower_components)/ }, {test: /\.ts$/, loader: ''ts-loader?cacheDirectory'', exclude: /(node_modules|bower_components)/ }, {test: /\.tsx$/, loader: ''ts-loader?cacheDirectory'', exclude: /(node_modules|bower_components)/ }, {test: /\.scss$/, loaders: [''style'', ''css'', ''sass'']}, {test: /\.png$/, loader: ''file-loader''}, {test: /\.jpg$/, loader: ''file-loader''}, {test: /\.jpeg$/, loader: ''file-loader''}, {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: ''file-loader?mimetype=image/svg+xml''}, {test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff"}, {test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff"}, {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/octet-stream"}, {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader"}, ] }, plugins: [ new CopyWebpackPlugin ([ { from: ''src/images'', to: ''images'' } ]), new webpack.optimize.CommonsChunkPlugin(''lib'', ''lib.js''), new HtmlWebpackPlugin ({ inject: true, template: ''src/index.html'' }), new webpack.NoErrorsPlugin() ]};
和这个tsconfig.json文件:
{ "compilerOptions": { "jsx": "preserve", "noImplicitAny": true, "module": "commonjs", "removeComments": false, "sourceMap": true, "target": "es5" }, "files": [], "exclude": [ "node_modules", "dist" ]}
答案1
小编典典第一个问题与 Martin 提到的“ jsx”配置有关。将“ jsx”设置为“反应”。
第二个问题与您的代码有关。像这样更改它:
class DiviAppBar extends React.Component<Props, State> ...
为道具创建一个界面,为状态创建另一个界面。如果没有,请使用空对象。
class DiviAppBar extends React.Component<{}, {}> ...
Ajax 和 XML: 将 Ajax 用于聊天-使用 Ajax 和 PHP 创建聊天应用程序
了解如何使用 Asynchronous JavaScript™ + XML (Ajax) 和 PHP 在 Web 应用程序中建立聊天系统。您的客户不需要下载或安装任何专门的即时消息通讯软件,就能和您及其他客户讨论网站的内容。
web 2.0 一词出现以来,开发人员都在说社区。不论您是否认为这有点夸大其辞,但让用户或读者能够方便地实时讨论页面主题或者销售的产品,这一想法还是很吸引人的。但是怎么办呢?能否在推销产品的页面中加入聊天,而不必让客户安装任何特殊的软件包括 adobe flash player 呢?当然!实践证明,用免费的现成工具如 php、mysql、动态 html (dhtml)、ajax 和 prototype.js 库就能完全做到。
不再罗嗦了,让我们立即开始吧。
本文转自:IBM developerWorks 中国
请点击此处查看全文
Ajax.BeginForm()没有工作MVC – 未捕获的javascript错误 – 意外的令牌(
我创建了Model类MyModel:
public class MyModel { [required] public string Name { get; set; } public int iexnum { get; set; } public InMyModel inMyModel { get; set; } public string selectedCombo { get; set; } public List<string> collection { get; set; } } public class InMyModel { public string Name { get; set; } public int Num { get; set; } }
我在我的布局中添加了这两个脚本:
<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
这是我的形式:
@{ Html.EnableClientValidation(); } @using (Ajax.BeginForm("MyFunction","Home",new AjaxOptions { HttpMethod = "POST",OnBegin = "function(){ loadingPanel.Show(); }",OnComplete = "function(){ loadingPanel.Hide(); }",UpdateTargetId = "mycontent",InsertionMode = InsertionMode.Replace },new { id = "validationForm",@,})) { <div id="mycontent"> @Html.Partial("_ajaxForm",Model) </div> }
当我运行应用程序并按下表单我得到javascript uncaught错误,如在此截图中:
正如您所看到的,jquery.unobstusive.ajax.min.js中存在未被捕获的错误
有人帮忙!?
解决方法
OnBegin = "function(){ loadingPanel.Show(); }",
我改成了:
OnBegin = "onBegin",OnComplete = "onEnd",
并在我的javascript文件中实现这些功能,这是工作!
Angular App中的语法错误:意外的令牌<
在我做了一个微小的改变之后,我在本地运行了应用程序并且工作正常.然后我构建了项目并将dist文件夹复制到Web服务器.问题是,当我尝试访问该应用时,我在Chrome检查器中收到以下错误:
Uncaught SyntaxError: Unexpected token < inline.1a152b6….bundle.js:1 Uncaught SyntaxError: Unexpected token < polyfills.1553fdd….bundle.js:1 Uncaught SyntaxError: Unexpected token < vendor.94d0113….bundle.js:1 Uncaught SyntaxError: Unexpected token < main.d6f56a1….bundle.js:1
所以,它似乎是一个错位的字符,但在我的本地环境中应用程序工作正常我没有在控制台上收到任何警告或错误消息..
关于javascript – jQuery AJAX JSONP错误“意外的令牌”的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于.tsx webpack编译失败:意外的令牌<、Ajax 和 XML: 将 Ajax 用于聊天-使用 Ajax 和 PHP 创建聊天应用程序、Ajax.BeginForm()没有工作MVC – 未捕获的javascript错误 – 意外的令牌(、Angular App中的语法错误:意外的令牌<的相关信息,请在本站寻找。
本文标签: