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);
}
});

解答:

@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(看页面源代码)的更多相关文章

  1. Invalid regular expression flags 错误

    找到写正则表达式的地方,检查是不是写了一个非法的正则表达式. Invalid regular expression flags

  2. react-native start error Invalid regular expression:

    详细错误: error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\]. ...

  3. Syntax error on token "Invalid Regular Expression Options", no accurate corr

    今天导入项目一个js文件报这个错 Syntax error on token "Invalid Regular Expression Options", no accurate c ...

  4. Uncaught SyntaxError: Invalid Unicode escape sequence异常处理

    今天碰到一个问题,页面报错:Uncaught SyntaxError: Invalid Unicode escape sequence ,{index:'operate',name:'operate' ...

  5. myeclipse中导入js报如下错误Syntax error on token "Invalid Regular Expression Options", no accurate correc

    今天在使用bootstrap的时候引入的js文件出现错误Syntax error on token "Invalid Regular Expression Options", no ...

  6. Uncaught SyntaxError: Invalid shorthand property initializer

    $.ajax({ url : '../../collateralQuery/getCollateralQueryDetail', type : 'POST', data : {}, dataType ...

  7. js文件报错Syntax error on token "Invalid Regular Expression Options", no accurate correction

    Syntax error on token "Invalid Regular Expression Options", no accurate correction 1.选中报错的 ...

  8. Invalid regular expression: unmatched parentheses

    Unmatched ) in Javascript regular expression您的某些字符串包含错误')'.你需要逃避这个.这是这样做的功能: function escapeRegExp(s ...

  9. Uncaught SyntaxError: Invalid or unexpected token

    出现错误的地方:在Jquery中,调用有参数的方法,动态传递参数时报错 出现错误的原因: 动态传递参数的时候,参数中有换行符 错误的解决:参数传递之前,将换行符替换 var  temp = model ...

随机推荐

  1. 1.3 Quick Start中 Step 4: Send some messages官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 4: Send some messages Step : 发送消息 Kaf ...

  2. JS/CSS 各种操作信息提示效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. codeforces 1037E. Trips(倒叙)

    题目传送门: 解题思路: 正着搞好像有点恶心. 反着搞. 一边删一边搞,从崩坏的地方开始,入度--. 最后dfs崩坏,更新答案. 注意要把边删掉防止重复崩坏. 代码: #include<cstd ...

  4. Qt之模型/视图(自己定义button)

    简述 衍伸前面的章节,我们对QTableView实现了数据显示.自己定义排序.显示复选框.进度条等功能的实现.本节主要针对自己定义button进行解说.这节过后,也希望大家对自己定义有更深入的了解.在 ...

  5. ajax中的POST和GET传值

    ajax中的POST和GET传值 转自:http://www.cnblogs.com/jtome/archive/2008/12/04/1347864.html Ajax中我们经常用到get和post ...

  6. ajax利用php上传图片

    <script type="text/javascript"> window.onload = function(){ document.getElementById( ...

  7. Rick's RoTs -- Rules of Thumb for MySQL--转载

    原文地址:http://mysql.rjweb.org/doc.php/ricksrots Brought to you by Rick James Here are 160+ tips, trick ...

  8. [React] Close the menu component when click outside the menu

    Most of the time, your components respond to events that occur within the component tree by defining ...

  9. js进阶 12 jquery事件汇总

    js进阶 12 jquery事件汇总 一.常用事件 页面载入事件 ready() 文档就绪事件(当 HTML 文档就绪可用时) 鼠标事件 click() 触发.或将函数绑定到指定元素的 click 事 ...

  10. eclipse编译器错误、警告设置

    颜色配置步骤:Window->Preferences->General->Editors->Text Editors->Annotations