Here is my code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebClient._Default" %>
<!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="Scripts/jquery-1.4.1.min.js" />
<script type="text/javascript" language="javascript">
var count = 0;
function Start()
{
setInterval("ReadNotification()", 1000);
}
function ReadNotification()
{
alert(++count);
}
</script>
</head>
<body onload="return Start();">
</body>
</html>
I just run this code and received a classic error:
Microsoft JScript runtime error: 'Start' is undefined
I dont't know why, because I really defined this method.
How can I solve this problem ?
Thank you very much.
Looks like the script tag for jquery is not closig properly unless you put a tag to close it, which renders those objects not readable, which gives you the error.
Code below, hope this helps.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebClient._Default" %>
<!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="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script>
var count = 0;
function Start()
{
setInterval("ReadNotification()", 5000);
};
function ReadNotification()
{
alert(++count);
};
</script>
</head>
<body onload="return Start();">
</body>
</html>
Related
<!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>Example</title>
<script type="text/javascript">
var myRequest = new XMLHttpRequest();
function loadXMLDoc(url)
{
myRequest.onreadystatechange = onResponse;
myRequest.open("GET", url, true);
myRequest.send();
}
function onResponse()
{
if(myRequest.readyState == 4 && myRequest.status == 200)
document.getElementById("A").innerHTML = myRequest.responseXML.documentElement.getElementsByTagName("color")[1].childNodes[0].nodeValue;
}
</script>
</head>
<body>
<p>Response: <span id="A"></span></p>
<button onclick="loadXMLDoc('example.xml')">Get Color</button>
</body>
</html>
a.meaning of the value true in myRequest.open("GET", url, true).
b. What values exists for the myRequest.readyState field, and what do they mean?
c. After the Get Color button is clicked, which portion of the example.htm code is updated?
d. If the XML file being accessed to get the color data has the following code:
<color_list>
<color>Red</color>
<color>Green</color>
<color>Blue</color>
</color_list>
sketch the Web browser page display of the example.htm page after the Get Color button is pressed and the page is updated.
I am trying to retrieve the output from the a URL using XMLHTTP GET:
The output in the browser when I hit the url directly is the following:
{
"Titles": {
"resultCount": 37680,
"moreResources": true
}
}
The ASP code on test.asp I am using is:
<%#language=JScript%>
<%
var objSrvHTTP;
objSrvHTTP = Server.CreateObject ("Msxml2.ServerXMLHTTP.6.0");
objSrvHTTP.open ("GET","http://someipaddress:8080/Publisher/Titles/Paging/0,0,tc?output=json", false);
objSrvHTTP.send ();
Response.ContentType = "application/json";
Response.Write (objSrvHTTP.responseText);
%>
The results displayed in browser from hitting test.asp is:
<!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>something</title>
</head>
<body>
{
"Titles": {
"resultCount": 37698,
"moreResources": true
}
}
</body>
</html>
I am looking to have just the data between the body tags returned, or even better just the value for "resultCount". Any help would be much appreciated.
You need to remove the HTML markup, when reading JSON data it should be nothing but valid JSON in the request response.
I have the following JSP page:
<%#page import="com.myPath.JSPHelper"%>
<%#page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=utf-8">
<meta name="keywords" content="${jspHelper.getKeywordsMetatag()}">
</head>
<body>
<%
JSPHelper jspHelper = new JSPHelper();
jspHelper.loadData(request.getAttribute("id").toString()); // load data from database
%>
<script type="text/javascript">
<%=jspHelper.getScriptContent()%>
</script>
</body>
</html>
What I'm trying to do is to fill in the contents of the keywords meta tag using a function getKeywordsMetatag() that is defined in a companion class `JSPHelper.java'.
But this is not working, I get the following error:
The function getKeywordsMetatag must be used with a prefix when a default namespace is not specified
I'm new to JSP so I've tried many things without success.
What am I doing wrong here?
What really bothers me is that the function getScriptContent() perfectly works, dumping javascript code in the html page. Why does getScriptContent() work but not getKeywordsMetatag()?
Thanks!
I would move the declaration of jspHelper up above its first use. I would also drop the ${} syntax but that might not be necessary.
<%#page import="com.myPath.JSPHelper"%>
<%#page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
JSPHelper jspHelper = new JSPHelper();
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="<%=jspHelper.getKeywordsMetatag()%>">
</head>
<body>
<%
jspHelper.loadData(request.getAttribute("id").toString()); // load data from database
%>
<script type="text/javascript">
<%=jspHelper.getScriptContent()%>
</script>
</body>
</html>
I have a made a contract with an adserver to serve ads on my website and the html snippet they give me does not validate, I am having a hard way trying to make it validate.
My header is transitional.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The html code I was given is the following.
<script language="javascript" type="text/javascript">iwsrcplus="http://codenew.impresionesweb.com/r/banner_iw.php?idrotador=82140&tamano=160x600&lgid="+((new Date()).getTime() % 2147483648) + Math.random(); document.write("<scr"+"ipt language=javascript type=text/javascript src="+iwsrcplus+"></scr"+"ipt>");</script><noscript><iframe src="http://alt.impresionesweb.com/noscript.php?tam=160x600&idp=82140&ref=82140&cod=160915" width="160" height="600" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe></noscript>
It does not validate just by changing the & to &s;.
You have to change the & symbols into...
&
Then post whatever other errors you get.
EDIT:
I validated all of your code as follows...
<!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>
</head>
<body>
<script language="javascript" type="text/javascript">
//<![CDATA[
iwsrcplus="http://codenew.impresionesweb.com/r/banner_iw.php?idrotador=82140&tamano=160x600&lgid="+((new Date()).getTime() % 2147483648) + Math.random(); document.write("<scr"+"ipt language=javascript type=text/javascript src="+iwsrcplus+"></scr"+"ipt>");
//]]>
</script>
<noscript><iframe src="http://alt.impresionesweb.com/noscript.php?tam=160x600&idp=82140&ref=82140&cod=160915" width="160" height="600" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe></noscript>
</body>
</html>
I am loading the values coming from database via a json object using java struts,
but the values are not populating in my extjs grid: I keep getting an empty grid.
I have included my code below.
home.jsp
A button will be there on this page. On clicking the getvalues.jsp should come.
In getvalues.jsp an extgrid should be presen with the content coming from database
<%# page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<!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>
</head>
<body>
<form action="getvalues.do">
<input type="submit"></input>
</form>
</body>
</html>
Below is my Java code. I am populating a JSON object with the values from my database.
public class Json extends Action {
#Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
// TODO Auto-generated method stub
ArrayList<Employee> emp=new ArrayList<Employee>();
Myservice serve=new Myservice();
emp=serve.getemployeesservice();
Iterator<Employee> empitr=emp.iterator();
JSONArray json=new JSONArray();
JSONObject JSONobj=new JSONObject();
while(empitr.hasNext()){
JSONObject jobj=new JSONObject();
Employee empl=new Employee();
empl=empitr.next();
jobj.put("empid",empl.getEmpid());
jobj.put("empname",empl.getEmpname());
json.add(jobj);
}
JSONobj.put("employee",json);
System.out.println(JSONobj.toString());
return mapping.findForward("success");
}
}
getvalues.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!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>
<link rel="stylesheet" type="text/css" href="css/ext-all.css">
<script type="text/javascript" src="js/ext-base.js"></script>
<script type="text/javascript" src="js/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
var store=new Ext.data.JsonStore({
proxy:new Ext.data.HttpProxy({
url:'http://localhost:8080/JsonExample/getvalues.do'
}),
reader:new Ext.data.JsonReader({
root:'employee',
fields:['empid','empname']
})
});
store.load();
var recs=store.getRange();
alert(recs.length);
var grid = new Ext.grid.GridPanel({
title:'employee information',
columns: [{
header:"employeeid",
width:100,
dataIndex:'empid',
sortable:true
},{
header:"employeename",
width:100,
dataIndex:'empname',
sortable:true
}],
store: store,
width:300,
height:300,
renderTo:Ext.getBody()
});
});
</script>
</head>
<body>
hi
</body>
</html>
But the values are not being populated for some reason. Please help me solve this issue.
Thanks in advance!
I'm not good at Java. But, I suspect, your JSON list is not sent to client, you are just printing, but not including it in response.