Почему значение переменной удаляется в файле js. когда я открываю jquery fancy box?

#javascript #jquery #html

#javascript #jquery #HTML

Вопрос:

У меня есть два файла .js и HTML. Я инициализирую значение переменной из одного файла .js в другой файл .js. В HTML-файле у меня есть Jquery fancy box. Когда я открываю Jquery fancy box. Инициализированный valriable удаляется, почему я не знаю ребят. пожалуйста, помогите с этим.

JS:

 function createEventDlg() {
      $.fancybox({
             href: "events/createEvent",
             type: "iframe", // <-- whatever content image, inline, swf, etc
             width: 600,
             afterClose: openEventImageUpdate
      });
   }
  

HTML:

 <ul  class="nav navbar-nav navbar-left">
                            <li class="li-search-logged">
                            <!-- id="selectedValueId" -->
                                <select  id="selectSearch">
                                    <option selected>Events</option>
                                    <option>Connections</option>
                                    <option>DFA Users</option>
                                </select>
                                <input type="text" id="auto-complete-tag" class="form-control" placeholder="Find Events, People, and Connections" />
                                <button class="btn btn-positive" type="button"></button>
                            </li>
                            <li class="li-btn"><input type="button" value="Create" class="btn btn-positive" onclick='createEventDlg();' /></li>
                            <li class="li-btn"><input type="button" value="Browse" class="btn btn-positive" onclick="loadBrowseEventPage()" /></li>
                            <li class="li-btn"><input type="button" value="DFA" class="btn btn-positive" onclick="loadDFA()" /></li>
                        </ul>
  

Browse.js:

Здесь переменная appRootUrl имеет значение. Например: «/app» и это вызывает метод в уведомлениях. метод init() в js. Затем Notifications.js объект инициализируется. Моя проблема заключается в том, когда я открываю jquery fancy box. Инициализированное значение переменной удаляется, почему я не знаю. Я буду использовать это значение переменной для вызова Jquery ajax. потому что у меня есть много методов в notifications.js. Эти методы будут использовать это значение переменной. пожалуйста, помогите мне.

  $( document ).ready(function() {
  <%
 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  Properties properties = new Properties();
  properties.load(classLoader.getResourceAsStream("app.properties"));
  %>
  var te = '${appRootUrl}';
  console.log('App root ulr : '   te);
  notifications.init('${appRootUrl}', "<%= properties.getProperty("node.server")%>");    
});
  

Notifications.js:

 var notifications = {
    appRootUrl : "something",
    nodeServer : "something",
    resource: {
        user: {
            findById: "/users/findbyid",
            getAlerts: "/users/getalerts",
            acceptChat: "/users/acceptchatinvite",
            declineChat: "/users/declinechatinvite",
            acceptFriend: "/users/acceptconnectioninvite",
            declineFriend: "/users/declineconnectioninvite",
            clearAlert: "/users/clearAlert",
            get: "/users/getuser",
            getEventPrivateChatHistory: "/users/eventPrivateChatHistory",
            eventPrivateSend: "/users/eventPrivatesend",
            dfaSend: "/users/dfasend",
            eventRestart: "/users/eventrestart",
            getFriendState: "/users/getFriendState",
            getDfaHistory: "/users/dfahistory",
            makeUserRelationshipNone: "/users/makerelationshipnone"
        },
        event: {
            getEventApprovedUsers: "/events/getApprovedUsers",
            getDfaGroupChatHistory: "/events/getGroupchatHistory",
            updateGroupChatMsgUrl: "/events/saveGroupchat",
            get: "/events/getEvent"
        }
    },
    init: undefined
};

notifications.init = function (appRootUrl, nodeServer) {
    console.log('appRootUrl : '   appRootUrl);
    console.log('nodeServer : '   nodeServer);

    notifications.appRootUrl = appRootUrl;
    notifications.nodeServer = nodeServer;
    console.log('notifications : '   JSON.stringify(notifications));
};
  

Ответ №1:

Наконец, я понял, что ответ заключается в том, что я должен инициализировать значение из Jquery fancy box. Потому что Jquery fancy box действует как текущий JSP. До того, как оно было инициализировано из browse.jsp. Когда пользователь нажимает Jquery fancy box. Он загружает JqueryFancyBox.Файл JSP. Там я должен инициализировать значение.

Пример кода здесь:

JqueryFancyBox.jsp:

 <c:url var="appRootUrl" value="/"/>
$(function () {
            <%
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            Properties properties = new Properties();
            properties.load(classLoader.getResourceAsStream("app.properties"));
            %>
            notifications.init("${appRootUrl}", "<%= properties.getProperty("node.server")%>");
});