eric2323223
eric2323223

Reputation: 3628

Ajax.updater problem

I am new to JavaScript and here is a problem when I trying out prototype.

I want to update sample.jsp with Ajax.updater after the it is loaded, but it doesn't work. Here the source of smaple.jsp.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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">
        <title>JSP Page</title>
        <script src="prototype.js"></script>
        <script>
            function f1(){
                var ajax = new Ajax.updater(
                {success: 'state'},'part.html'
                ,{method:'get'});
            }
            document.observe('dom:loaded', function() {
                f1();
            });

        </script>
    </head>
    <body>
        state:
        <div id="state"></div>
        <br>
    </body>
</html>

Could anyone tell me what's wrong with my code?

Upvotes: 1

Views: 1115

Answers (2)

eric2323223
eric2323223

Reputation: 3628

I have tried another one and it works

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <title>AJAX Zip Checker </title>
        <link rel="stylesheet" href="style.css" type="text/css" />
        <script src="prototype.js"></script>
        <script type="text/javascript" language="JavaScript">
            function checkZip() {
                if($F('zip').length == 5) {
                    var url = 'checkzip.jsp';
                    var params = 'zip=' + $F('zip');
                    var ajax = new Ajax.Updater(
                    {success: 'zipResult'},
                    url,
                    {method: 'get', parameters: params, onFailure: reportError});
                }
            }
            function reportError(request) {
                $F('zipResult') = "Error";
            }
        </script>
    </head>
    <body>

        <label for="zip">zip:</label>
        <input type="text" name="zip" id="zip" onkeyup="checkZip();" />
        <div id="zipResult"></div><p/>

    </body>
</html>

checkzip.jsp

<%
        String zip = request.getParameter("zip");
        if (zip.equals("10009")) {
%>
new york
<%} else {%>
unknown
<% }%>

Could anyone tell me the difference?

Upvotes: 0

Yonatan Karni
Yonatan Karni

Reputation: 977

try "Ajax.Updater" (capital U) for starters

also I recommend that you try working with firefox and the firebug plugin, it's a great way to debug your javascript

Upvotes: 1

Related Questions