Uncaught syntax error: invalid regular expression flags ( see page source code )
1. Summary
JS or jQuery errors look at the page source code, and all of a sudden the errors are very clear JS or jQuery errors
2. Uncaught syntax error: invalid regular expression flags
This error occurs when the page uses Ajax in jQuery
1 $(document).ready(function(){
2 $("#b01").click(function(){
3 htmlobj=$.ajax({url:"/jquery/test1.txt",async:false});
4 $("#myDiv").html(htmlobj.responseText);
5 });
6 });
The answer to the Internet is:
@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.
look at the static HTML converted from the dynamic HTML of the next page (commonly known as the page source code): it’s easy to find the error