ajax to achieve mootools

2009-10-12  来源:本站原创  分类:AJAX  人气:369 

As we all know, ajax source code can be written directly to achieve, but it's a little cumbersome, and now the popular ajax framework ajax integrated functions, and to write very simple and convenient. Mootools of course, is no exception.
Request of mootools to achieve the functionality of XMLHttpRequest wrapper class, the following is a small example I wrote:
js:

function testPing(){
        var url = document.getElementById("url").value;
        var pingRequest = new Request({
                        method: "post",
                        url:    "../site/ping.do",
                        onSuccess:  function(responseText){
                            if(responseText=="success"){
                                document.getElementById("pingDiv").innerHTML =" This URL to ping  ";
                            }
                            else{
                                document.getElementById("pingDiv").innerHTML =" This URL will not be able to ping  ";
                            }
                        },
                        onFailure:  function(){
                            document.getElementById("pingDiv").innerHTML =" This URL will not be able to ping  ";
                        }
                    });

                        pingRequest.send("url="+ url);
    }

html:

<input type="text"  name="${status.expression}" value="$!{status.value}"/>
                <input type="button" name="ping" value=" Test link  " />
<div></div>

java code:

@RequestMapping("/site/ping.do")
    public void ping(@RequestParam("url") String url,ModelMap model, HttpServletResponse response) throws IOException {

        AjaxUtil ajaxUtil = new AjaxUtil();
        try {
            Ping ping = new Ping();
            boolean pingFlag = ping.pingServer(url,5);
            if(pingFlag){
                ajaxUtil.ajaxOutput(response, "success");
            }else{
                ajaxUtil.ajaxOutput(response, "error");
            }
        } catch (Exception e) {
            ajaxUtil.ajaxOutput(response, e.toString());
        }
    }

public class AjaxUtil {

    /**
     *  Copies the object into a JSON string
     * @param object
     * @return
     */
    public String convert2JSONString(Object object) {
        JSONArray jsonObject = JSONArray.fromObject(object);
        return jsonObject.toString();
    }

    /**
     *  Returns the AJAX calls results
     * @param response
     * @param outputString
     * @throws java.io.IOException
     */
    public void ajaxOutput(HttpServletResponse response, String outputString) throws IOException {
        response.setContentType("text/html; charset=utf-8");
        response.getWriter().write(outputString);
        response.getWriter().flush();
    }
}
相关文章
  • ajax to achieve mootools 2009-10-12

    As we all know, ajax source code can be written directly to achieve, but it's a little cumbersome, and now the popular ajax framework ajax integrated functions, and to write very simple and convenient. Mootools of course, is no exception. Request of

  • Several popular AJAX framework jQuery, Mootools, Dojo, Ext JS Comparative 2009-07-14

    Several popular AJAX framework jQuery, Mootools, Dojo, Ext JS Comparative I encountered the Internet in many parts of this article, are not clearly marked out the author, find it strange? ? If you are the author of this article, it is very sorry, but

  • The use of Ajax to achieve a simple dynamic query example 2010-04-11

    Using Ajax for a simple dynamic query example. This example is the use of Ajax asynchronous transmission. Asynchronous transfer object by sending requests and receiving responses. Request for server-side component, where the use of Servlet implementa

  • Using Ajax to achieve long-connection (analog Push) 2010-08-29

    Transfer from: http://blog.csdn.net/liyb5619/archive/2010/06/25/5693107.aspx Many programs can be achieved through a long socket connection, to achieve real-time push message. However, http requests are generally short connection, a request, and you

  • Four popular AJAX framework jQuery, Mootools, Dojo, ExtJS contrast 2010-10-29

    AJAX is the cornerstone of web2.0, and now several popular open source AJAX Web framework, such as: jQuery, Mootools, Dojo, Ext JS and so on, then we in the end under what circumstances the use of that framework? The following is a excerpt of the dat

  • spring 2.5 mvc annotations ajax to achieve 2008-05-08

    spring 2.5 a lot of use of the mvc annotations, reducing the xml configuration file, so that spring to use more simple and In the following I have a spring 2.5 mvc annotations an ajax implementation. LEI Wu Luan First, look at the class action config

  • Ext.Ajax.request achieve synchronous interaction 2010-08-12

    The first step first into the ext-basex.js page <link rel="stylesheet" href="js/ext/resources/css/ext-all.css"> <script type="text/javascript" src="js/ext/adapter/ext/ext-base.js"> </ script> <s

  • ajax to achieve user authentication 2010-10-12

    <script type="text/javascript"> var xhr; / / Initialize the xhr object / / Return value: 1: IE, 2, Mozila, 0: create xhr error; function createXHR () { / / 1 to create xhr object. if (window.ActiveXObject) { xhr = new ActiveXObject ("

  • Ajax to achieve linkage effects 2010-03-29

    Action function: public void writeAjaxObject(Object data) { PrintWriter out = null; try { out = getResponse().getWriter(); out.print(data); out.flush(); } catch (IOException e) { e.printStackTrace(); } finally { out.close(); } } public String gettrad

  • Fade to use AJAX to achieve special effects (back Qinbo) 2009-09-04

    0.jquery.js I put down below you can download the 1. <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> </ title> <lin

  • . Net refresh using AJAX to achieve local 2010-04-07

    Front: <div> <asp:ScriptManager runat="server" EnableScriptLocalization="true" EnablePageMethods="true"> </asp:ScriptManager> <asp:UpdatePanel runat="server" UpdateMode="Conditional"&g

  • ajax to achieve three linkage menu 2010-08-03

    Insert database statement create table COUNTRY ( NAME VARCHAR2 (100) not null, TYPE NUMBER not null ) ; alter table COUNTRY add constraint PRIMARY_KEY primary key (TYPE); insert into COUNTRY (NAME, TYPE) values ('China', 1); insert into COUNTRY (NAME

  • Ruby ajax to achieve two linked menu 2011-05-13

    view the page code: <label> Season <span> * </ span> </ label> <% = Select ('season', 'id', Season.all.collect {| t | [t.name, t.id]}, {: include_blank => true}, {"Onchange" => remote_function ( : With => &quo

  • AJAX without refreshing the chat room to achieve (download the attachment to the cabinet) 2009-07-05

    Before writing a small chat room of DEMO, a blog, in addition http://lvp.javaeye.com/blog/343236, download the attachment provided. However, this example brought about automatically refresh the page to experience a sense of bad, and when the contents

  • ajax.json and java to achieve a direct transfer List 2010-06-14

    Since the project needs to get back in the List object ajax inside value, since no previous contact with json so I have to first pass a string and then pointing a substring in js to achieve. Leisure time to explore a bit on the List object json accep

  • 128 ajax / javascript framework 2010-07-30

    128 ajax / javascript framework AJAX framework can help us to rapidly develop through JavaScript calling WebService (Server Page) pages, but not required to submit the entire page. Recent web applications use AJAX to improve the pages can be interact

  • 128 ajax / javascript frameworks 2010-07-30

    128 ajax / javascript framework AJAX framework can help us to rapidly develop through JavaScript calling WebService (Server Page) pages, but not required to submit the entire page. Recent web applications use AJAX to improve the pages can be interact

  • A classic english Rails AJAX sorting and paging sample 2009-03-20

    This is a classic (in my opinion ^ _ ^) is used to display, ajax call to sort, search and paging example. This sample is characterized by the process of writing put considerable wordily, designed to kill Mother. So very good understanding, very prima

  • At ajax application data exchanged between 2009-04-20

    In this article, I will introduce one for the Ajax client and server to transfer data between the main method, and compare the traditional model of Web applications with the Ajax model differences. In addition, the text will also be explored at the s

  • Topsy Ajax Six: Ajax user login 2009-10-16

    This will be the production of the reader to start from scratch with a AJAX Login DEMO, program features, business is very simple, so I do not need with you to explain things in this regard, we look at how to use AJAX to achieve the registry, the pur