Hello! I have an Ajax script wich works well on a page, but when I use it in another page I got the error "function not defined"
this one works well : - <script type="text/javascript">
-
function details(var1, var2)
-
{
-
var html;
-
-
xmlhttp = new XMLHttpRequest();
-
-
xmlhttp.onreadystatechange=function()
-
{
-
h = document.getElementById("log").innerHTML;
-
h = h + xmlhttp.readyState + " / " + xmlhttp.status + "<br/>";
-
if(xmlhttp.readyState==4 && (xmlhttp.status==200||xmlhttp.status==0))
-
{
-
html = xmlhttp.responseText;
-
document.getElementById("res").innerHTML=html;
-
}
-
}
-
xmlhttp.open("GET","detailsCity?Pays="+var1+"&Name="+var2,true);
-
xmlhttp.send();
-
}
-
</script>
- <a href=""onMouseOver= "details('${CDet.res.name}','${CDet.res.cap}')"
-
onMouseOut="details('${CDet.res.name}','${CDet.res.cap}')">
-
${CDet.res.cap}</a><br>
-
But when I put it in this page (I give the entier page here after) i got the "not defined" error: - <?xml version="1.0" encoding="UTF-8" ?>
-
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-
<%@ page
-
language="java"
-
contentType="text/html; charset=UTF-8"
-
pageEncoding="UTF-8"
-
%>
-
<%@ page import="java.awt.*" %>
-
<jsp:useBean id="CList" scope="session" class="fr.n7.asi.cs.model.CLBean"></jsp:useBean>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
<html>
-
-
<head>
-
<link rel="stylesheet" type="text/css" href="sts.css" />
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-
-
-
-
<script type="text/javascript">
-
function details(var1, var2)
-
{
-
var html;
-
-
xmlhttp = new XMLHttpRequest();
-
-
xmlhttp.onreadystatechange=function()
-
{
-
h = document.getElementById("log").innerHTML;
-
h = h + xmlhttp.readyState + " / " + xmlhttp.status + "<br/>";
-
if(xmlhttp.readyState==4 && (xmlhttp.status==200||xmlhttp.status==0))
-
{
-
html = xmlhttp.responseText;
-
document.getElementById("res").innerHTML=html;
-
}
-
}
-
xmlhttp.open("GET","detailsCity?Pays="+var1+"&Name="+var2,true);
-
xmlhttp.send();
-
}
-
</script>
-
-
-
-
<title>CountryList View (JSP)</title>
-
</head>
-
-
<body background="http://bytes.com/images/terres.jpeg">
-
-
Bonjour <% out.println(session.getAttribute("nom"));%> ! <a href="deconnect">se deconnecter</a><br><br><br>
-
-
<h1>LISTE DES PAYS COMMENCANT PAR PREFIXE</h1>
-
-
<table border="1">
-
<c:forEach var="citem" items="${CList.res}">
-
<tr><td>
-
<a href="details?Code=${citem.code}">${citem.name}</a><br/>
-
</td></tr>
-
</c:forEach>
-
-
<tr><td>
-
<a href=""onMouseOver= "details('aaaa','bbbb')"
-
onMouseOut="details('aaaa','aaaa')">
-
aaaaaa</a><br>
-
</td></tr>
-
-
-
</table>
-
<h3><a href="prefCreate.jsp">retour au menu principal</a><br/></h3>
-
</body>
-
</html>
-
-
do somenone see what is happening with my code ?
thx a lot
3 2607
In your code line 29 and 30 is useless moreover generating the errors
And your line 34 is seeking for a object with id res
ok thx I modified according to your remarks but it was still not working.
I solved the problem, actually I put both javascript scripts in the first jsp page (before I had the first jsp calling a second one, both had ajax code (two separated functions)). I am not sure it is possible to put some javascript functions in some code returned by the XMLhttpRequest objet... i have to hunt on this.
Yes Very much possible,
But its little tricky
To do that you will have to separate the javascript code and then create a new script object and the write those code to that object, or you can simply use JQuery
as example -
<script>
-
function send_req(uri)
-
{
-
$.ajax(
-
{
-
url: "targepage?parameter=parameter",
-
type: 'POST',
-
dataType: 'html',
-
data: uri,
-
timeout: 90000,
-
success: function(html, data)
-
{
-
$("#Reply").html(html);}
-
});
-
}
-
</script>
-
<div id='Reply'>
-
</div>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: rashmi |
last post by:
how to use static function defined in one file in another file is that
impposiible in 'c '
|
by: thisis |
last post by:
Hi All,
i have this.asp page:
<script type="text/vbscript">
Function myFunc(val1ok, val2ok)
' do something ok
myFunc = " return something ok"
End Function
</script>
|
by: jamo |
last post by:
Hi all, can anyone help with this problem.
I want to call an Ajax function from a list menu *onchange*, my javascript is not good.
Code below:
Menu:
<select name="menu1"...
|
by: shivendravikramsingh |
last post by:
hello friends,
actually i have a problem in using conditional statement in ajax function
i m tring to describe my problem properly,what i want when i select a value form a combo its vlue is passed...
|
by: shivendravikramsingh |
last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
|
by: jack21 |
last post by:
I have a main window containing a list of items along with some buttons. If the user clicks the 'View' button, I open a child window containing the details of the item along with 'Approve' and...
|
by: Shalini Bhalla |
last post by:
i have 2 tables bank master and branch details having bankcode as a common feild .
i have designed a form in which i am filtering branches according to a particular bank code using ajax ,...
|
by: panos100m |
last post by:
Hi on page load a javascript functions (timedCount()) is executed (timer) which executes another javascript function (ajax function:findprov(divtowrite) ) in turn this calls a php file to query a...
|
by: BaseballGraphs |
last post by:
Hello,
I am trying to update data on my webpage using AJAX. The idea is when a user clicks a checkbox the data will be updated.
This is the code that I have so far:
<script...
|
by: Soniad |
last post by:
Hello,
I am using ajax to get details from DB.The page where I have written DB queries has include files containing and JavaScript variables defined in it.After fetching the required data I...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |