Javascript 在页面顶部获取脚本,以便获取错误,如$not define

Javascript 在页面顶部获取脚本,以便获取错误,如$not define,javascript,jquery,nopcommerce-4.0,Javascript,Jquery,Nopcommerce 4.0,我正在使用asp.net核心代码在主视图中弹出并附加html和js文件,但我遇到错误,如$not found,如果有人知道如何解决,请帮助 我的ActionFilter代码:- private readonly IStoreContext _storeContext; private readonly ISettingService _settingService; private readonly ILogger _logger; private readonl

我正在使用asp.net核心代码在主视图中弹出并附加html和js文件,但我遇到错误,如$not found,如果有人知道如何解决,请帮助

我的ActionFilter代码:-

    private readonly IStoreContext _storeContext;
    private readonly ISettingService _settingService;
    private readonly ILogger _logger;
    private readonly ILocalizationService _localizationService;
    private readonly IWorkContext _workContext;
    private readonly ITopicService _topicService;
    private readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;

    #endregion

    #region const

    public PopupEngageFilterAttribute()
    {
        this._storeContext = EngineContext.Current.Resolve<IStoreContext>();
        this._settingService = EngineContext.Current.Resolve<ISettingService>();
        this._logger = EngineContext.Current.Resolve<ILogger>();
        this._localizationService = EngineContext.Current.Resolve<ILocalizationService>();
        this._workContext = EngineContext.Current.Resolve<IWorkContext>();
        this._topicService = EngineContext.Current.Resolve<ITopicService>();
        this._newsLetterSubscriptionService = EngineContext.Current.Resolve<INewsLetterSubscriptionService>();
    }

    #endregion

    #region methods

    public void PopupEngageOnResultExecuted(ActionExecutedContext filterContext)
    {
        var storeId = _storeContext.CurrentStore.Id;

        LicenseImplementer licenseImplementer = new LicenseImplementer();

        // load plugin settings
        var _setting = _settingService.LoadSetting<PopupEngageSetting>(storeId);
        var allStoreSettings = _settingService.LoadSetting<PopupEngageSetting>(0);

        //check plugin is enabled or not
        if (_setting.PopupEngageEnabled)
        {
            // check license 
            //if (!licenseImplementer.IsLicenseActive(allStoreSettings.LicenseKey, allStoreSettings.OtherLicenseSettings))
            //    return;

            StringBuilder sb = new StringBuilder();
            string bioepEngageScript = string.Empty;
            string popupEngageView = string.Empty;
            string popupEngageScript = string.Empty;
            string newsLetterScript = string.Empty;

            // get current customer
            var customer = _workContext.CurrentCustomer;

            // check customer cart
            string customerCart = Convert.ToString(customer.HasShoppingCartItems);

            // set cookie for customer cart 
            filterContext.HttpContext.Response.Cookies.Append("CustomerCart", customerCart, new CookieOptions() { Path = "/", HttpOnly = false, Secure = false });

            if(customerCart == "True")
            {
                // get bioep script file
                Stream bioepScriptFile = Assembly.GetExecutingAssembly().GetManifestResourceStream("Nop.Plugin.XcellenceIt.PopupEngage.Script.bioep.min.js");
                if (bioepScriptFile != null)
                    using (StreamReader reader = new StreamReader(bioepScriptFile))
                    {
                        bioepEngageScript = reader.ReadToEnd();
                    }

                // get PopupEngage script
                string path = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Environment.CurrentDirectory.ToString(), "Plugins"), "XcellenceIt.PopupEngage"), "Script"), "PopupEngage.js");

                if (File.Exists(path))
                {
                    popupEngageScript = File.ReadAllText(path);
                }

                // check current customers role
                var customerRole = customer.CustomerRoles.Where(x => x.Name == "Guests").FirstOrDefault();
                if (customerRole != null)
                {
                    // get Popup View file
                    string popupEngageViewFile = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Path.Combine(Environment.CurrentDirectory.ToString(), "Plugins"), "XcellenceIt.PopupEngage"), "Views"), "PopupEngage"), "PopupEngageNewsLetter.html");
                    if (File.Exists(popupEngageViewFile))
                    {
                        popupEngageView = File.ReadAllText(popupEngageViewFile);
                    }

                    // get NewsLetter Script file
                    Stream newsLetterScriptFile = Assembly.GetExecutingAssembly().GetManifestResourceStream("Nop.Plugin.XcellenceIt.PopupEngage.Script.NewsLetter.js");
                    if (newsLetterScriptFile != null)
                        using (StreamReader reader = new StreamReader(newsLetterScriptFile))
                        {
                            newsLetterScript = reader.ReadToEnd();
                        }
                }
                else
                {
                    // get Popup View file
                    string popupEngageViewFile = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Path.Combine(Environment.CurrentDirectory.ToString(), "Plugins"), "XcellenceIt.PopupEngage"), "Views"), "PopupEngage"), "PopupEngage.html");
                    if (File.Exists(popupEngageViewFile))
                    {
                        popupEngageView = File.ReadAllText(popupEngageViewFile);
                    }
                }

                var topicBody=string.Empty;

                // get topic from settings
                var topic = _setting.TopicName;
                if (!string.IsNullOrEmpty(topic))
                {
                    // get topic by system name
                    var topicRecord = _topicService.GetTopicBySystemName(topic);
                    if(topicRecord != null)
                    {
                        topicBody = topicRecord.Body;
                    }
                }

                // replace new line with slash and double coute with single coute
                popupEngageView = popupEngageView.Replace(Environment.NewLine, String.Empty).Replace("\"", "'");
                topicBody = topicBody.Replace(Environment.NewLine, String.Empty).Replace("\"", "'");

                // append script
                sb.Append("<script type=\"text/javascript\" src=\"/wwwroot/lib/jquery-1.10.2.min.js\">\n\t");
                sb.Append(bioepEngageScript);
                sb.Append(popupEngageScript);
                sb.Append("$(\"" + popupEngageView + "\").insertAfter(\".newsletter\");");
                sb.Append("$('.popupengage_popupmsg').html(\"" + topicBody + "\");");
                sb.Append(newsLetterScript);
                sb.Append("</script>\n");
                var bytes = Encoding.ASCII.GetBytes(sb.ToString());
                filterContext.HttpContext.Response.Body.WriteAsync(bytes,0, bytes.Length);
            }
        }
    }
    #endregion
private readonly IStoreContext\u storeContext;
专用只读ISettingService\u设置服务;
专用只读ILogger\u记录器;
专用只读ILocalizationService\u localizationService;
私有只读IWorkContext\u workContext;
私有只读ITopicService_topicService;
private readonly InewsletteSubscriptionService\u NewsletteSubscriptionService;
#端区
#区域常数
公共PopupEngageFilterAttribute()
{
这是。_storeContext=EngineContext.Current.Resolve();
这是。_settingService=EngineContext.Current.Resolve();
此._logger=EngineContext.Current.Resolve();
此._localizationService=EngineContext.Current.Resolve();
这是。_workContext=EngineContext.Current.Resolve();
此._topicService=EngineContext.Current.Resolve();
这是._newslettesubscriptionservice=EngineContext.Current.Resolve();
}
#端区
#区域方法
public void PopupEngageOnResultExecuted(ActionExecutedContext筛选器上下文)
{
var storeId=\u storeContext.CurrentStore.Id;
LicenseImplementer LicenseImplementer=新的LicenseImplementer();
//加载插件设置
var\u setting=\u settingService.LoadSetting(storeId);
var allStoreSettings=\u settingService.LoadSetting(0);
//检查插件是否已启用
如果(_setting.popuengageenabled)
{
//检查许可证
//如果(!licenseImplementer.IsLicenseActive(allStoreSettings.LicenseKey、allStoreSettings.OtherLicenseSettings))
//返回;
StringBuilder sb=新的StringBuilder();
string=string.Empty;
string popupEngageView=string.Empty;
string popupEngageScript=string.Empty;
string脚本=string.Empty;
//获取当前客户
var customer=\u workContext.CurrentCustomer;
//检查客户购物车
字符串customerCart=Convert.ToString(customer.hashoppingcartItems);
//为客户购物车设置cookie
filterContext.HttpContext.Response.Cookies.Append(“CustomerCart”,CustomerCart,new CookieOptions(){Path=“/”,HttpOnly=false,Secure=false});
如果(customerCart==“True”)
{
//获取BEOP脚本文件
Stream bioPScript file=Assembly.getExecutionGassembly().GetManifestResourceStream(“Nop.Plugin.XcellenceIt.PopupEngage.Script.bioep.min.js”);
if(bioPScript文件!=null)
使用(StreamReader=新StreamReader(BioEPScript文件))
{
bioPengagescript=reader.ReadToEnd();
}
//获取PopupEngage脚本
字符串path=path.Combine(path.Combine(path.Combine(path.Combine(Environment.CurrentDirectory.ToString(),“Plugins”),“XcellenceIt.PopupEngage”),“Script”),“PopupEngage.js”);
if(File.Exists(path))
{
popupEngageScript=File.ReadAllText(路径);
}
//检查当前客户角色
var customerRole=customer.CustomerRoles.Where(x=>x.Name==“来宾”).FirstOrDefault();
if(customerRole!=null)
{
//获取弹出视图文件
字符串popupEngageViewFile=Path.Combine(Path.Combine(Path.Combine(Path.Combine)(Path.Combine(Environment.CurrentDirectory.ToString(),“Plugins”),“XcellenceIt.PopupEngage”),“Views”),“PopupEngageNewsLetter.html”);
if(File.Exists(popupEngageViewFile))
{
popupEngageView=File.ReadAllText(popupEngageViewFile);
}
//获取新闻稿脚本文件
Stream NewsletteScriptFile=Assembly.GetExecutionGassembly().GetManifestResourceStream(“Nop.Plugin.XcellenceIt.PopupEngage.Script.NewsLetter.js”);
if(newslettescriptfile!=null)
使用(StreamReader=新StreamReader(时事通讯脚本文件))
{
newslettescript=reader.ReadToEnd();
}
}
其他的
{
//获取弹出视图文件
字符串popupEngageViewFile=Path.Combine(Path.Combine(Path.Combine)(Path.Combine(Path.Combine)(Path.Combine(Environment.CurrentDirectory.ToString(),“Plugins”),“XcellenceIt.PopupEngage”),“Views”),“PopupEngage”),“PopupEngage.html”);
if(File.Exists(popupEngageViewFile))
{
popupEngageView=File.ReadAllText(popupEngageViewFile);
}
}
var topicBody=string.Empty;
//从设置中获取主题
var topic=\u setting.TopicName;
如果(!string.IsNullOrEmpty(主题))
{
//按系统名称获取主题
var topicRecord=\u topicService.GetTopicBySystemName(主题);
如果(topicRecord!=null)
{
topicBody=topicRecord.Body;
}
}
//将新行替换为斜线,将双线替换为单线
popupEngageView=popupEngageView.Replace(Environment.NewLine,String.Empty);
topicBody=topicBody.Replace(Environment.NewLine,String.Empty);
//附加脚本
sb.追加(“\n\t”);
<script>jquery.js </scrpt>
<script>main.js </scrpt>