• Uncaught SyntaxError: Invalid regular expression flags(看页面源代码)


    Uncaught SyntaxError: Invalid regular expression flags(看页面源代码

    一、总结

    js或者jquery方面的错误看页面源代码,一下子错误就很清晰了

    二、Uncaught SyntaxError: Invalid regular expression flags

    页面用jquery中的ajax的时候出现这个错误

    1 $(document).ready(function(){
    2   $("#b01").click(function(){
    3   htmlobj=$.ajax({url:"/jquery/test1.txt",async:false});
    4   $("#myDiv").html(htmlobj.responseText);
    5   });
    6 });

    网上找的解答是:

    @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 Syntax error .

    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.

  • 相关阅读:
    “山大地纬杯”第十二届山东省ICPC大学生程序设计竞赛部分个人题解
    OpenLayer4——地图拉伸导致事件丢失问题
    OpenLayer4——贝塞尔曲线插值算法
    OpenLayer4——多边形遮罩层
    OpenLayer4——获取鼠标点击的坐标
    OpenLayer4——坐标间距计算
    OpenLayer4——定位到坐标位置
    你的第一个大数据 helloword
    记一次SparkUI的使用记录
    # vue脚手架3使用 cesium
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/9083831.html
Copyright © 2020-2023  润新知