Servlet response in popup window - javascript

I have a JSP page which opens up a popup using JS.
The popup opens the following JSP page.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="/ArchiveSearch/resources/css/messageDetail.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Message detail</title>
</head>
<body>
<div class="wrapper">
<h1>Message Details</h1>
<div class="messageMeta1">
<div><span class="label">Sender:</span> <c:out value="${messageid}" /></div>
<div><span class="label">Receiver:</span></div>
<div><span class="label">Subject:</span></div>
<div><span class="label">Attachments:</span></div>
</div>
<div class="messageMeta2">
<div><span class="label">Case ID:</span></div>
<div><span class="label">Date:</span>${messagedate}</div>
</div>
<div class="messageContent">
</div>
</div>
</body>
</html>
My problem is that when JS opens the webpage the values that are passed from the servlet don't show up on the JSP page. But when I check HTML reponse under Firebug the HTML is rendered correctly. My question is how do I get the Servlet in the popup window correctly?
JS:
$('#searchResults tbody tr').live('dblclick', function () {
var aData = table.fnGetData( this,0 );
$.ajax({
url: "MessageDetail",
type: "POST",
data: "messageid=" + aData,
succes: function(data) {
}
});
window.open(myjsppage.jsp, "_blank", "width=600,height=600");
});
Popup window has know knowledge of the request made before, how can I fix this?
EDIT
I tried something like this:
succes: function(data) {
gData = data;
}
});
var popup = window.open("messageDetail.jsp", "_blank", "width=600,height=600");
popup.document.write(gData);
});
I think I am on the right way, but i'm not completely there yet. Undefined is printed in the popup now, which means the variable isn't filled.

It's not a good way of doing this, but if you want your code to work you must use it like this:
success: function(data) {
gData = data;
var popup = window.open("messageDetail.jsp", "_blank", "width=600,height=600");
popup.document.write(gData);
}
});
});
Put your open code inside success method.
Also you wrote success with one 's', please fix it.

Related

autocomplete list in input text box is not coming

So i am having problem on auto completion feature of jquery. My requirement is to show Json data in auto completion . Json data is coming from java class in jsp page .This code is working fine but nothing is coming in text box as i type something.
This is my jsp page
<%#page import="com.practise.autoComplete.AutoComplete"%>
<%#page import="net.sf.json.JSONObject"%>
<%#page import="net.sf.json.JSON"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# page import="java.util.*"%>
<%
AutoComplete autoComplete=new AutoComplete();
JSONObject jsonObject=autoComplete.autoComp();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script src="./JS/jquery-1.4.2.min.js"></script>
<script src="/JS/jquery.autocomplete.js"></script>
<script>
function lookup(inputString) {
alert("inside lookup");
if (inputString.length == 0) {
$('#suggestions').hide();
} else {
var object=<%=jsonObject%>
var data= JSON.stringify(object);
if (data.length > 0) {
$("#inputauto").autocomplete({
source: data
});
}
}
}
</script>
<head>
<body>
<div>
<form>
<div>
<br /> Enter Name to see autocomplete <input
type="text" size="30" value="" id="inputauto"
onkeyup="lookup(this.value);" />
</div>
</form>
</div>
</body>
</html>
This is my java file
package com.practise.autoComplete;
import net.sf.json.JSONObject;
public class AutoComplete {
public JSONObject autoComp() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("1", "peter");
jsonObject.put("2", "nadia");
jsonObject.put("3", "jack");
jsonObject.put("4", "areena");
return jsonObject;
}
}

Can not get innerHTML to work?

Why does my code not work? Shouldn't it print 222 to the element with ID p2?
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%#page import="java.io.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function compareData()
{
document.getElementById('p1').innerHTML = "111";
var inputs = document.getElemementsByTagName("input");
// why can't I display the "222" here??
document.getElementById('p2').innerHTML = "222";
}
</script>
</head>
<body>
<p id="p1"> a </p>
<p id="p2"> b </p>
<input type="button" onclick="compareData()" value="hello"/>
</body>
</html>
You have mis-spelled getElemementsByTagName. This results in a js error, thereby your code stops execution at that line.
Correct it as getElementsByTagName. Then your code would work fine.
Why you are using this? var inputs = document.getElemementsByTagName("input");
My fiddle
And you can use the way you are using like this : My fiddle but it was not working because Elements spelling is wrong document.getElemementsByTagName
It should be document.getElementsByTagName
You have a typo on this line:
var inputs = document.getElemementsByTagName("input");
What you want is probably this:
var inputs = document.getElementsByTagName("input");
It could be that the typo stops the execution of the script, and therefor the line after is never run.
Remove following line and it will work...
var inputs = document.getElemementsByTagName("input");

Ajax in Tinybox 2

I have a Tinybox 2 popup opening when clicking 'register'. The user has then to choose if he/she wants to register as a user or a performer. I'd like to show a different registration page for each, but first asking it, so handling with ajax would be the best. It can be done, as shown here, in the 5th example. Here is my current code:
<!doctype html>
<html>
<head>
<title>Regisztrációs típus kiválasztása</title>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="../css/soon.css"/>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
</head>
<body>
<div id="teljes">
<h1>Miként szeretnél regisztrálni?</h1>
<div id="felhasznalo">
Felhasználóként
</div>
<div id="eloado">
Előadóként
</div>
</div>
<script type="text/javascript">
$('#felireg').click(function() {
$.get("../php/register.php");
});
</script>
</body>
</html>
Thanks!
If i understand correctly, you want to make an ajax call to your registration file named "register.php" and show this in a Tinybox
$('#felireg').click(function() {
TINY.box.show({
url:'../php/register.php',width:300,height:150
})
});
This should work.
//EDIT :
Assuming your file returns only html:
$('#felireg').click(function() {
$.get("../php/register.php", function(data)
{
TINY.box.fill(data);
});
});
This should update the current Tinybox

why is the fb.event not fired?

I am trying to trigger the FB subscribe event, but the alert does not work.
The FB like button displays but when I click the like button there is no alert:
Code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="facebook.aspx.cs" Inherits="iFrame.facebook" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="//connect.facebook.net/en_US/all.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<iframe src="http://www.facebook.com/plugins/like.php?app_id=&href=www.goal.com"
scrolling="no" frameborder="0" style="border: none; overflow: hidden; width: 47px;
height: 20px;" allowtransparency="true"></iframe>
</div>
</form>
</body>
</html>
<script type="text/javascript">
FB.Event.subscribe('edge.create',
function (response) {
alert('You liked the URL: ' + response);
});
</script>
You need to be using the XFBML version of the Like button or else the event isn't detectable.
If the Javascript SDK didn't initialise the Like button then it also won't have access to the event fired. Use the XFBML version of the Like button instead of the iframe version and the rest of your code should work - it looks fine.

problem with javascript with JSP

Hey all i am trying to use javascript with my jsp file as under:
JSP File:
<?xml version="1.0" encoding="UTF-8" ?>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>title goes here</title>
<link rel="icon" href="scripts/assets/favicon.ico" type="image/x-icon"/>
<%--
Ajax code to refresh the main page's contents.
This ajax code is specific to the home page not
for all so it is kept outside the main script file.
--%>
<script type="text/javascript" src="scripts/AjaxRefresh.js"></script>
<script type="text/javascript" src="scripts/MainScript.js"></script>
<link rel="stylesheet" type="text/css" href="scripts/MainStyle.css" />
</head>
<body>
<div class="mainContainer">
<div class="header">
header
</div>
<div class="leftNavigation">
Home
<br/>
Home
<br/>
Home
<br/>
Home
<br/>
Home
<br/>
Home
<br/>
Home
<br/>
Home
</div>
<div class="mainContentArea">
Main Content Area
</div>
<div class="rightTabBar">
Right Tab Bar
</div>
<div class="footer">
Footer
</div>
</div>
</body>
</html>
and the MainScript.js file is as under:
window.onload = initAll();
function initAll(){
var navigationButton = document.getElementsByTagName("a");
for ( var int = 0; int < navigationButton.length; int++) {
if(navigationButton[int].className == "navigationButton")
navigationButton[int].onclick = animateLink;
}
}
function animateLink(){
this.className = "navigationButtonActive";
return false;
}
but when i tried to execute this code i found that javascript code is not working properly and with firebug i found the variable navigationBUtton is an empty array.
Actually i am from PHP background so don't know precisely the concepts of jsp so what sort of problem here is??
PS: I am using eclipse 3.5 with apache tomcat6 as web server in ubuntu 10.10 platform.
thanks :)
You're assigning the outcome of the function to the window.onload instead of letting it point to a function name.
Replace
window.onload = initAll();
by
window.onload = initAll;
or just do
window.onload = function() {
var navigationButton = document.getElementsByTagName("a");
for ( var int = 0; int < navigationButton.length; int++) {
if(navigationButton[int].className == "navigationButton")
navigationButton[int].onclick = animateLink;
}
}
See also:
window.onload documentation in MDC
Note that this problem is unrelated to JSP.

Categories

Resources