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.

最新文章

  1. hotCity 小程序城市选择器, 城市数据库可自己导出
  2. 【代码笔记】iOS-对iphone手机进行判断的一些函数
  3. Python成长笔记 - 基础篇 (一)python简介
  4. WPF 样式和行为
  5. Codeforce Round #215 Div2 C
  6. Spring 定时任务的配置
  7. linux中的工具
  8. ms sql server缓存清除与内存释放
  9. ubuntu 安装phpmyadmin
  10. require.js的使用的坑!
  11. 【百度地图API】交你如何用百度地图搜索自己的数据!不需数据库!
  12. Hibernate的三种缓存
  13. java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
  14. 浅析Web缓存
  15. 使用ODP.NET连接Oracle数据库
  16. C# winfrom容器布局与工具栏&&右键菜单栏&&隐藏显示小图标的的简单事件
  17. Docker CE 各安装方法
  18. crm——stark组件核心原理
  19. 超全PHP学习资源整理:入门到进阶系列
  20. c#调用webservices

热门文章

  1. 关于大数据项目创建时所需setting.xml(博主推荐)
  2. UVA 12333 Revenge of Fibonacci
  3. BZOJ3672: [Noi2014]购票(CDQ分治,点分治)
  4. 多线程中的"断点"续传《notify()和wait()》
  5. Accelerated C++:通过演示样例进行编程实践——练习解答(第9章)
  6. hdu4605Magic Ball Game 树状数组
  7. Java Web学习总结(18)——JSP标签
  8. Valgrind的用法
  9. 接口如何使用(以笑话大全api为例)
  10. python3 登录验证小程序,同一用户输错三次密码,锁定账户