Developersland

Teknoloji ve Yazılım Blogu

  • Yazıtipi boyutunu arttır
  • Varsayılan yazıtipi boyutu
  • Yazıtipi boyutunu azaltır

Ext JS AJAX

Ext js ajaxI will talk about how to send ajax request to the url and how you can get data in server side (java code) in this tutuorial. We send Ajax request with function which named Ext.Ajax.request. This function takes following arguments.

url: This data gives information about which url will take this request. In our example www.oursite.com/yenikullaniciekle will take this request.

params: This data includes variables which we will send to the server side code. In our example we assign isimsoyisim to content of textBox which id is "isimsoyisim" . If request will responsed properly success part will work if some error occurs failure part will work.


Ext.Ajax.request({

url : 'yenikullaniciekle',

     params : {

     isimsoyisim:Ext.getCmp('isimsoyisim').getValue(),

     },

     success : function(response) {

obj = Ext.util.JSON.decode(response.responseText);

     Ext.MessageBox.alert("Başarılı");

     },

     failure : function(response) {

     Ext.MessageBox.alert("Bir hata oluştu!");

     }

});


The following code is server side JAVA code. Which will take this http request for www.oursite.com/yenikullaniciekle


@RequestMapping(value="/yenikullaniciekle")

public void yenikullaniciekle(HttpServletRequest req, HttpServletResponse resp) throws IOException{

KanBagiscisi bagisci=new KanBagiscisi();

bagisci.setIsimsoyisim(req.getParameter("isimsoyisim"));


JSONObject obj = new JSONObject();

obj.put("success", true);

resp.getWriter().print(obj);

}

We can get variables which sent from Ext JS scripts with java code using req.getParameter("isimsoyisim").

We have to send our response in JSON format to Ext JS scripts. We create new JSONObject instance and using put(key, value) method of this instance to put some data in this JSONObject. We assign true value to "success" variable in our example.

We can access this variable using obj = Ext.util.JSON.decode(response.responseText); and we will access success variable with obj.success.

We will add obj to rsponse with the following code resp.getWriter().print(obj);




 

Yorum ekle


Güvenlik kodu
Yenile