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.
最新文章
- hotCity 小程序城市选择器, 城市数据库可自己导出
- 【代码笔记】iOS-对iphone手机进行判断的一些函数
- Python成长笔记 - 基础篇 (一)python简介
- WPF 样式和行为
- Codeforce Round #215 Div2 C
- Spring 定时任务的配置
- linux中的工具
- ms sql server缓存清除与内存释放
- ubuntu 安装phpmyadmin
- require.js的使用的坑!
- 【百度地图API】交你如何用百度地图搜索自己的数据!不需数据库!
- Hibernate的三种缓存
- java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
- 浅析Web缓存
- 使用ODP.NET连接Oracle数据库
- C# winfrom容器布局与工具栏&;&;右键菜单栏&;&;隐藏显示小图标的的简单事件
- Docker CE 各安装方法
- crm——stark组件核心原理
- 超全PHP学习资源整理:入门到进阶系列
- c#调用webservices
热门文章
- 关于大数据项目创建时所需setting.xml(博主推荐)
- UVA 12333 Revenge of Fibonacci
- BZOJ3672: [Noi2014]购票(CDQ分治,点分治)
- 多线程中的&;quot;断点&;quot;续传《notify()和wait()》
- Accelerated C++:通过演示样例进行编程实践——练习解答(第9章)
- hdu4605Magic Ball Game 树状数组
- Java Web学习总结(18)——JSP标签
- Valgrind的用法
- 接口如何使用(以笑话大全api为例)
- python3 登录验证小程序,同一用户输错三次密码,锁定账户