Simple Javascript Script doesn't work in Konqueror (Ajax)

Samir van de Sand samir.vds at googlemail.com
Sun Dec 9 19:37:16 GMT 2007


Hello everyone,

in my class we started learning Ajax. Therefore our teacher provided some very 
simple code to show us how XMLHttpRequest works. Basically we have a HTML 
form where you can choose between "Elephant" and "Africa". If the user clicks 
on Elephant an image of an elephant is displayed, if the user clicks on 
Africa an image of the african map is displayed.

Unfortunately, this doesn't work on Konqueror (it's working fine in Firefox). 
Could somebody tell me why ?


Code:


bilder.html

<html>
<script language="JavaScript" src="bilder.js"></script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
<head>
<body>
<br />
<form name="f">
Wählen sie einen Bildnamen aus.
<select name="bild" size="1" onClick="sndReq()">
<option>Elephant</option>
<option>Afrika</option>
</select>
</form>
<br />
<span id="hs"></span>
</body>
</html>

bilder.js

var resObjekt = new XMLHttpRequest();
function sndReq() {
  for(i=1;i<=16;i++){
    if(this.document.f.bild.options[i-1].selected){
    resObjekt.open('get', 'bilder.jsp?dateiname='+i,true);
    resObjekt.onreadystatechange = handleResponse;
    resObjekt.send(null);
    break;
} } }
function handleResponse() {
  if(resObjekt.readyState == 4){
    document.getElementById("hs").innerHTML =
    resObjekt.responseText;
} }

bilder.jsp (backend)

<%@ page language="java" errorPage="error.jsp" pageEncoding="UTF-8"%>
<% request.getParameter("dateiname"); %>
<%
   switch(new Integer(request.getParameter("dateiname")).intValue()) {
     case 1: %> <img src="images/Elephant.jpg" /><%break;
     case 2: %> <img src="images/Afrika.jpg" /><%break;
     default: %> <img src="images/Elephant.jpg" />
<%}%>


regards Samir

btw: I'm not subcribed to the mailing list.




More information about the kfm-devel mailing list