Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

$ not defined #8958


User avatar
0
rrader26 created

I have a strange issue. I am currently using the latest version of ASPNETZERO JQuery version. I am attempting to get SurveyJS to run properly. My issue is I am unable to get it to render and I believe it has something to do with JQuery. Attached is my view code

@using Service.Authorization @using Service.Web.Areas.App.Startup @{ ViewBag.CurrentPageName = AppPageNames.Common.FormQuestionaire; } @section Scripts { <script src="https://surveyjs.azureedge.net/1.7.4/survey.jquery.js"></script> <script src="https://surveyjs.azureedge.net/1.7.4/surveyjs-widgets.js"></script> <script src="https://surveyjs.azureedge.net/1.7.4/surveyjs-widgets.js"></script> <script abp-src="/view-resources/Areas/App/Views/FormQuestionaire/Index.js"></script> } @section Styles { <link href="https://surveyjs.azureedge.net/1.7.4/modern.css" type="text/css" rel="stylesheet" /> @<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet" />@ }

<link href="https://surveyjs.azureedge.net/1.7.4/modern.css" type="text/css" rel="stylesheet" />

<script> //(function ($) { //jQuery($ => { $(document).ready(function () { alert("Inside Jquery");

    Survey
        .StylesManager
        .applyTheme("modern");

    var json = {

    };

    window.survey = new Survey.Model(json);

    survey
        .onComplete
        .add(function (result) {
            document
                .querySelector('#surveyResult')
                .textContent = "Result JSON:\n" + JSON.stringify(result.data, null, 3);
        });

    survey.render("surveyElement");
});
//});

</script> <div class="kt-content kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor"> <div class="kt-subheader kt-grid__item"> <div class="@(await GetContainerClass())"> <div class="kt-subheader__main"> <h3 class="kt-subheader__title"> <span>@L("FormQuestionaire")</span> </h3> <span class="kt-subheader__separator kt-subheader__separator--v"></span> <span class="kt-subheader__desc"> @L("FormFieldsQuestionaireHeaderInfo") </span> </div> <div class="kt-subheader__toolbar"> <div class="kt-subheader__wrapper">

            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;@(await GetContainerClass()) kt-grid__item kt-grid__item--fluid&quot;&gt;
    &lt;div class=&quot;kt-portlet kt-portlet--mobile&quot;&gt;
        &lt;div class=&quot;kt-portlet__body&quot;&gt;
            &lt;div id=&quot;surveyElement&quot;&gt;&lt;/div&gt;
            &lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

</div>

From this you can see I am referencing the JS files in the @section Scripts. When I run the code in the browser I am getting the error $ is not defined. I have attempting to define in my scripts section (function ($) jQuery($ => {});); with no luck. How can I ensure JQuery is references properly?


8 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @rrader26

    JQuery must be included by default to your page. Could you share the location of your cshtml file ? Is it under "Areas/AppAreaName/Views/**" ?

    Thanks,

  • User Avatar
    0
    rrader26 created

    the files are under Areas/App/Views/FormQuestionaire.

    I have tried to add JQuery to my page but than I get other errors that pop up. So I assumed it was added by default somewhere within the project.

    What is the proper way to add JQuery?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Sorry, I couldn't read your first post correctly. You need to put below script into Scripts section;

    @section Scripts
    {
    	$(document).ready(function () {
    		alert("Inside Jquery");
    		// other code blocks
    	});
    }
    
  • User Avatar
    0
    rrader26 created

    I have tried that before and it did not work either. Seems odd to me. I would get $ is not defined

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @rrader26

    Is it possible to share your project via email with [email protected] ? We can find the problem faster in that way.

  • User Avatar
    0
    rrader26 created

    I sent an email with a link to the source code

  • User Avatar
    0
    ismcagdas created
    Support Team

    Moving custom scripts into @section Scripts fixes the problem.

  • User Avatar
    0
    marble68 created

    I got SurveyJS to work in mine - same (Core / Jquery) -

    However - it's dependencies have a LOT of vulnerabilities.

    I don't know if that's a big problem, but it sort of scared me away from it.