3

In one JSP file I have an element:

<div id="mydialog"></div>

I have an anchor tag <a href='#' id="#newentry">

On the click of the anchor tag I have some jQuery events to open a dialog and load in a p tag into the dialog:

jQuery.noConflict();
       var $ = jQuery;
       var myDialog;
       jQuery(document).ready(function(){
           operation                                        =   "addEntryPage";
           document.forms[0].selectedUserdataIndex.value    =   "";
           document.forms[0].search.value                   =   "";
           myDialog = jQuery('#mydialog').dialog({
                autoOpen: false,
                modal: true,
                width: 200,
                height: 200
            }); 
            jQuery('#newentry').click(function(e){
                e.preventDefault();
                myDialog.load('/console/admin/NewFile.jsp #p').dialog("open");
                return false;
            });    
        });

I'm trying to load the p tag from NewFile.jsp into my dialog div. Here is NewFile.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p>Sample text.</p>
</body>
</html>

The dialog opens but the sample text does not appear inside. In the developer tools I'm seeing a 200 response code from the load() GET and the preview shows the sample text. Any ideas?

Edit:

Changed NewFile.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p id="target">Sample text.</p>
</body>
</html>

and:

myDialog.load('/console/admin/NewFile.jsp #target').dialog("open");
5
  • 3
    #p is looking for a id="p" element. You only have a p. Either you need to add the id, or change the selector to ...NewFile.jsp p Commented Jun 23, 2020 at 20:57
  • 1
    That being said, returning an entire HTML page for this seems wasteful. If you just want to get some text from the server return JSON or XML instead, or include the text from the server side when the page is loaded and toggle its visibility when the a is clicked Commented Jun 23, 2020 at 20:57
  • Thanks for your quick response, I'll make the necessary changes, and update based on my results. This task is actually just an exercise in order for me to gain understanding for my "main" goal. The last question I posted illustrates the task further, but it effectively aims to replace window.showModalDialog(). I haven't gotten any replies yet, I don't think there's a sturdy migration guide for IE5 applications to IE11.
    – omri
    Commented Jun 23, 2020 at 21:03
  • Yup, added id="target" to the p tag in the NewFile.jsp. Sample text now showing up, thanks, Rory.
    – omri
    Commented Jun 23, 2020 at 21:14
  • <a href='#' id="#newentry"> 👈 perhaps you want the ID to be newentry instead of #newentry
    – Phil
    Commented Jun 24, 2020 at 1:34

0