473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Ajax function not defined

2
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 :

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function details(var1, var2)
  3. {
  4.     var html;
  5.  
  6.     xmlhttp = new XMLHttpRequest();
  7.  
  8.     xmlhttp.onreadystatechange=function()
  9.     {
  10.         h = document.getElementById("log").innerHTML;        
  11.         h = h + xmlhttp.readyState + " / " + xmlhttp.status + "<br/>";
  12.         if(xmlhttp.readyState==4 && (xmlhttp.status==200||xmlhttp.status==0))
  13.         {
  14.             html = xmlhttp.responseText;
  15.             document.getElementById("res").innerHTML=html;
  16.         }
  17.     }
  18.     xmlhttp.open("GET","detailsCity?Pays="+var1+"&Name="+var2,true);
  19.     xmlhttp.send();
  20. }
  21. </script>
Expand|Select|Wrap|Line Numbers
  1.   <a href=""onMouseOver= "details('${CDet.res.name}','${CDet.res.cap}')" 
  2.               onMouseOut="details('${CDet.res.name}','${CDet.res.cap}')">
  3.               ${CDet.res.cap}</a><br>
  4.  
But when I put it in this page (I give the entier page here after) i got the "not defined" error:


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3. <%@ page 
  4. language="java" 
  5. contentType="text/html; charset=UTF-8"
  6. pageEncoding="UTF-8"
  7. %>
  8. <%@ page import="java.awt.*"  %>
  9. <jsp:useBean id="CList" scope="session" class="fr.n7.asi.cs.model.CLBean"></jsp:useBean>    
  10.  
  11. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  12. <html>
  13.  
  14. <head>
  15. <link rel="stylesheet" type="text/css" href="sts.css" />
  16. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  17.  
  18.  
  19.  
  20. <script type="text/javascript">
  21. function details(var1, var2)
  22. {
  23.     var html;
  24.  
  25.     xmlhttp = new XMLHttpRequest();
  26.  
  27.     xmlhttp.onreadystatechange=function()
  28.     {
  29.         h = document.getElementById("log").innerHTML;        
  30.         h = h + xmlhttp.readyState + " / " + xmlhttp.status + "<br/>";
  31.         if(xmlhttp.readyState==4 && (xmlhttp.status==200||xmlhttp.status==0))
  32.         {
  33.             html = xmlhttp.responseText;
  34.             document.getElementById("res").innerHTML=html;
  35.         }
  36.     }
  37.     xmlhttp.open("GET","detailsCity?Pays="+var1+"&Name="+var2,true);
  38.     xmlhttp.send();
  39. }
  40. </script>
  41.  
  42.  
  43.  
  44. <title>CountryList View (JSP)</title>
  45. </head>
  46.  
  47. <body background="http://bytes.com/images/terres.jpeg">
  48.  
  49. Bonjour <% out.println(session.getAttribute("nom"));%> ! <a href="deconnect">se deconnecter</a><br><br><br>
  50.  
  51. <h1>LISTE DES PAYS COMMENCANT PAR PREFIXE</h1>
  52.  
  53. <table border="1">
  54. <c:forEach var="citem" items="${CList.res}">
  55. <tr><td>
  56. <a href="details?Code=${citem.code}">${citem.name}</a><br/>
  57. </td></tr>
  58. </c:forEach>
  59.  
  60. <tr><td>
  61.   <a href=""onMouseOver= "details('aaaa','bbbb')" 
  62.               onMouseOut="details('aaaa','aaaa')">
  63.               aaaaaa</a><br>
  64.  </td></tr>    
  65.  
  66.  
  67. </table>
  68. <h3><a href="prefCreate.jsp">retour au menu principal</a><br/></h3>
  69. </body>
  70. </html>
  71.  
  72.  
do somenone see what is happening with my code ?
thx a lot
May 22 '11 #1
3 2607
johny10151981
1,059 1GB
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
May 23 '11 #2
jaylau
2
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.
May 23 '11 #3
johny10151981
1,059 1GB
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

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function send_req(uri)
  3. {
  4.  $.ajax(
  5.   {
  6.    url: "targepage?parameter=parameter", 
  7.    type: 'POST', 
  8.    dataType: 'html', 
  9.    data: uri, 
  10.    timeout: 90000,
  11.    success: function(html, data)
  12.        { 
  13.      $("#Reply").html(html);}
  14.     });
  15. }
  16. </script>
  17. <div id='Reply'>
  18. </div>
  19.  
May 24 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: rashmi | last post by:
how to use static function defined in one file in another file is that impposiible in 'c '
19
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>
5
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"...
1
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...
2
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...
3
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...
17
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 ,...
2
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...
4
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...
4
Soniad
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
0
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...
0
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...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.