|
|
|
Yazan
|
Konu: Basit Ajax Kütüphanesi (Okunma Sayısı 705 defa)
|
OnurPhp
Yeni Kullanıcılar
Offline
Mesaj Sayısı: 4
|
<script type="text/javascript"> /** * Ajax Asynchronous Javascript & XML * * Ajax Library * * Copyright (C) 2006 Onur Yerlikaya * LICENCE : This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * @category Core * @package Ajax * @author Onur Yerlikaya <onur.yerlikaya@linux.org.tr> * @version 0.0.1 * @link http://www.onuryerlikaya.com * @licence GNU General Public Licence - Version 2 * @copyright Onur Yerlikaya */
// XML Request Object var http = cReq();
// XML Reques Result var response = null;
/** * Create Request Object Function * * @return object */ function cReq() { // XML Request Object var xml; if(window.XMLHttpRequest) { xml = new XMLHttpRequest(); } else if(window.ActiveXObject) { try { xml = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { try { xml = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} } } // end if return xml; }
/** * Send Request Function * * @param array params Parametres for request * @param string url Request URL * @param string method Request Send Method ( GET || POST ) */ function sendReq(params,url,method) { // Checks Request Method if(method == "POST") { // Open POST Request http.open('POST',url,true); // Send Request Header http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); } else { // Open GET Request http.open('GET',url,true); } // Call function when state change http.onreadystatechange = handleResponse; // Send parametres.. http.send(params); }
/** * Handle Response */ function handleResponse() { // Check state if(http.readyState == 4) { // Check Server Status if(http.status == 200) { // Assign Response setRes(http.responseText); } else { // Give an alert for problem alert('Problem - handleResponse !'); } } }
function setRes(getResponse) { response = getResponse; }
function getRes() { return response; } </script>
Kullanım Şekli : İştek Gönder : sendReq(null,'oku.pp','GET');
Sonuç Al : sonuc = getRes(); alert(sonuc);
|
|
|
|
« Son Düzenleme: 14, 2007, 09:21:57 am Gönderen: OnurPhp »
|
Logged
|
|
|
|
mudkicker
Arif Ender
Admin
Offline
Mesaj Sayısı: 873
Mastered PHP
|
Merhaba,
Sana bir tavsiye, mümkün olduğunca fonksiyonlarını, methodlarını kolay anlaşılabilir ve görevi adından belirlenebilir şekilde adlandır. Uzun veya kısa olması aşırı önemli değil ama bu bir bakım kullanıcı-dostu bir kodlama olur.
Umarım daha da geliştirirsin. Eline sağlık.
|
|
|
|
|
Logged
|
|
|
|
sote
Yeni Kullanıcılar
Offline
Mesaj Sayısı: 5
PHP 5
|
eburhan'a gönder bence.  eyceks'ten daha kolay bir kütüphane arıyordu. 
|
|
|
|
|
Logged
|
Çalışmazsan, kazanamazsın... Denesen denesen başaramazsın...
|
|
|
|
 |
|