Uncaught SyntaxError: Invalid regular expression flags(看页面源代码)
Uncaught SyntaxError: Invalid regular expression flags(看页面源代码)
一、总结
js或者jquery方面的错误看页面源代码,一下子错误就很清晰了
二、Uncaught SyntaxError: Invalid regular expression flags
页面用jquery中的ajax的时候出现这个错误
$(document).ready(function(){
$("#b01").click(function(){
htmlobj=$.ajax({url:"/jquery/test1.txt",async:false});
$("#myDiv").html(htmlobj.responseText);
});
});
网上找的解答是:
@Url.Action only returns the action url's string, without quotes around it.
You'll need to wrap that url in quotes.
Replace:
url: @Url.Action("ReturnMethodTest", "HomeController"),
With:
url: '@Url.Action("ReturnMethodTest", "HomeController")',
// ^ ^
Otherwise, the file returned to the client will contain:
url: /HomeController/ReturnMethodTest,
Which isn't valid JS, nor what you want. The replacement gives the following result:
url: '/HomeController/ReturnMethodTest',
Which is a perfectly valid JavaScript string.
看了下页面动态html转换成的静态html(通俗说就是页面源代码):很容易就发现错误了

三、其它错误参照
问题:
public ActionResult ReturnMethodTest(int id)
{
string name = "John";
return Json( new {data=name});
}
I am trying to get data from this controller by using code below but I am getting
.
Can you please tell me what am I doing wrong?
$.ajax({
url: @Url.Action("ReturnMethodTest", "HomeController"),
data: {
id: 5,
},
success: function (data) {
console.log(data);
}
});
- 1
- My Code looks like this $.ajax({ url: '@Url.Action("ReturnMethodTest", "Home")', data: { id: 5, }, success: function (data) { console.log(data); } }); And firebug throws "500 internal Server Error" /i59.tinypic.com/5y96ok.png – Da Artagnan Jul 13 '15 at 7:13
解答:
@Url.Action only returns the action url's string, without quotes around it.
You'll need to wrap that url in quotes.
Replace:
url: @Url.Action("ReturnMethodTest", "HomeController"),
With:
url: '@Url.Action("ReturnMethodTest", "HomeController")',
// ^ ^
Otherwise, the file returned to the client will contain:
url: /HomeController/ReturnMethodTest,
Which isn't valid JS, nor what you want. The replacement gives the following result:
url: '/HomeController/ReturnMethodTest',
Which is a perfectly valid JavaScript string.
Uncaught SyntaxError: Invalid regular expression flags(看页面源代码)的更多相关文章
- Invalid regular expression flags 错误
找到写正则表达式的地方,检查是不是写了一个非法的正则表达式. Invalid regular expression flags
- react-native start error Invalid regular expression:
详细错误: error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\]. ...
- Syntax error on token "Invalid Regular Expression Options", no accurate corr
今天导入项目一个js文件报这个错 Syntax error on token "Invalid Regular Expression Options", no accurate c ...
- Uncaught SyntaxError: Invalid Unicode escape sequence异常处理
今天碰到一个问题,页面报错:Uncaught SyntaxError: Invalid Unicode escape sequence ,{index:'operate',name:'operate' ...
- myeclipse中导入js报如下错误Syntax error on token "Invalid Regular Expression Options", no accurate correc
今天在使用bootstrap的时候引入的js文件出现错误Syntax error on token "Invalid Regular Expression Options", no ...
- Uncaught SyntaxError: Invalid shorthand property initializer
$.ajax({ url : '../../collateralQuery/getCollateralQueryDetail', type : 'POST', data : {}, dataType ...
- js文件报错Syntax error on token "Invalid Regular Expression Options", no accurate correction
Syntax error on token "Invalid Regular Expression Options", no accurate correction 1.选中报错的 ...
- Invalid regular expression: unmatched parentheses
Unmatched ) in Javascript regular expression您的某些字符串包含错误')'.你需要逃避这个.这是这样做的功能: function escapeRegExp(s ...
- Uncaught SyntaxError: Invalid or unexpected token
出现错误的地方:在Jquery中,调用有参数的方法,动态传递参数时报错 出现错误的原因: 动态传递参数的时候,参数中有换行符 错误的解决:参数传递之前,将换行符替换 var temp = model ...
随机推荐
- 带你一分钟理解闭包--js面向对象编程(转载他人)
什么是闭包? 先看一段代码: function a(){ var n = 0; function inc() { n++; console.log(n); } inc(); inc(); } a(); ...
- Linux 常用解压缩归档命令
linux 常见压缩.归档工具 创建压缩工具 压缩工具 后缀 描述 compress/uncompress .Z 早期工具,现在不常见了 gzip/gunzip .gz 进几年比较火的工具 bzip2 ...
- jQuery自定义插件规范
<ul class="list"> <li>导航列表 <ul class="nav"> <li>导航列表1< ...
- HTML5手机应用的最大优势就是可以在网页上直接调试和修改
HTML5手机应用的最大优势就是可以在网页上直接调试和修改
- Vue 消息无缝滚动
vue实现消息向上无缝滚动效果 <ul class="new-list" :class="{anim:animate}" @mouseenter=&quo ...
- [Javascirpt AST] Babel Plugin -- create new CallExpression
The code we want to trasform: 2 ** 3; a ** b; a **b * c; a ** b ** c; (a+1) ** (b+1); transform to: ...
- HTML高级标签之表格标签
前面学习了一下HTML的经常使用标签, 今天開始高级标签之路! 一.表格标签 1.作用: 创建一张表格 2.各属性作用: <table cellspacing="0" cel ...
- 洛谷 P2693 [USACO1.3]号码锁 Combination Lock
P2693 [USACO1.3]号码锁 Combination Lock 题目描述 农夫约翰的奶牛不停地从他的农场中逃出来,导致了很多损害.为了防止它们再逃出来,他买了一只很大的号码锁以防止奶牛们打开 ...
- python opencv —— io(帧、图像、视频的读取与保存)
0. VideoCapture VideoCapture:构造函数: 常见成员函数: open:打开视频文件,或者捕获视频设备,该函数会首先调用 release() 函数以关闭已打开的文件或设备: P ...
- 【CS Round #48 (Div. 2 only)】Dominant Free Sets
[链接]h在这里写链接 [题意] 让你在n个点组成的集合里面选取不为空的集合s. 使得这里面的点没有出现某个点a和b,ax>=bx且ay>=by; 问你s的个数. [题解] 我们把这些点按 ...