-
İçerikler özgün değildir. Sadece sık sık lazım olan işime yarayacak olan notları almış olduğum kişisel bloğumdur.
8 Şubat 2014 Cumartesi
Ajax Get ve POST methodu ile XMLHTTPRequest
Usually only the GET method is used while creating Ajax apps. But there are several occasions when POST is necessary when creating a ajax request. This could be for several reasons. For example, POST request are considered more secure than GET request as creating a POST request is relatively harder than creating a GET request.
Requirements
- Create a XMLHTTPRequest Object that uses the POST method.
- See if the arguments passed to it appear in the '
$_POST' array in PHP.
Code
XMLHTTPRequest Object
For the sake of simplicity, we are going to create the XMLHTTPRequest object using the Firefox supported ' XMLHttpRequest()' function. I believe that you know the proper way of creating a cross-browser XMLHttpRequest object. If not, learn that first.var http = new XMLHttpRequest();
Using GET method
Now we open a connection using the GET method.
var url = "get_data.php";
var params = "lorem=ipsum&name=binny";
http.open("GET", url+"?"+params, true);
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(null);
I really hope that this much is clear for you - I am assuming that you know a bit of Ajax coding. If you don't, please read a ajax tutorial that explains these parts before continuing.POST method
We are going to make some modifications so POST method will be used when sending the request...
var url = "get_data.php";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
The first change(and the most obvious one) is that I changed the first argument of the open
function from GET to POST. Also notice the difference in the second
argument - in the GET method, we send the parameters along with the url
separated by a '?' character...http.open("GET",url+"?"+params, true);
But in the POST method we will use just the url as the second argument. We will send the parameters later.http.open("POST", url, true);
Some http headers must be set along with any POST request. So we set them in these lines...http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
With the above lines we are basically saying that the data send is in
the format of a form submission. We also give the length of the
parameters we are sending.http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
We set a handler for the 'ready state' change event. This is the same handler we used for the GET method. You can use the http.responseText here - insert into a div using innerHTML(AHAH), eval it(JSON) or anything else.http.send(params);
Finally, we send the parameters with the request. The given url is
loaded only after this line is called. In the GET method, the parameter
will be a null value. But in the POST method, the data to be send will
be send as the argument of the send function. The params
variable was declared in the second line as
"lorem=ipsum&name=binny" - so we send two parameters - 'lorem' and
'name' with the values 'ipsum' and 'binny' respectively.That's it. If you wish to see the working of this script, I have set up a demo page for Ajax using post.
Libraries
The above given methods are the manual way of doing things - you can automate this using the hundreds of Ajax libraries out there.jx
jx.load("get_data.php?lorem=ipsum&name=binny",handlerFunction,"text","POST");
Prototype
var myAjax = new Ajax.Request('get_data.php?lorem=ipsum&name=binny',{
method: 'post',
onComplete:handlerFunction
});
Dojo Toolkit
dojo.io.bind({
url: "get_data.php?lorem=ipsum&name=binny",
mimetype: "text/plain",
method: "POST",
load:handlerFunction
});
Yahoo! UI
var myAjax = YAHOO.util.Connect.asyncRequest('POST', 'get_data.php?lorem=ipsum&name=binny', {success:handlerFunction},"");
Mochikit
var ajmyAjax = doSimpleXMLHttpRequest('get_data.php?lorem=ipsum&name=binny').addCallback(handlerFunction);
Kaydol:
Kayıt Yorumları
(
Atom
)
search this website
email updates
Like us on facebook
Katkıda bulunanlar
Blogger tarafından desteklenmektedir.
Etiketler
- AJAX (3)
- alertbox (1)
- android (1)
- Asp.net (22)
- blogger (1)
- bootstrap (2)
- C# (1)
- Canvas (3)
- capture (2)
- datetime (1)
- dizüstü (1)
- dizüstü bilgisayardan interneti paylaştırmak (1)
- editör yapma (1)
- facebook api (1)
- Flash (1)
- format (1)
- geometri (6)
- google (1)
- Graf (1)
- Graf Teorisi (1)
- Hatalar (4)
- Html (1)
- html5 (2)
- iframe (1)
- ilköğretim (4)
- javascript (2)
- jquery (7)
- JSON (2)
- kablosuz (1)
- Karakter (1)
- Kodlama örnekleri (2)
- kütle (4)
- Laravel (2)
- laravel g-zip (1)
- Listbox (1)
- Matematik (20)
- matematikistan (2)
- matematikistan.net (16)
- mongoDB (1)
- msdos (1)
- mysql (4)
- netbeans (1)
- phonegap (1)
- php (3)
- php ile benzer tags (1)
- php similar tags (1)
- routing (2)
- Samsung (1)
- Save (1)
- Save Canvas (2)
- SOAP (1)
- tags (1)
- tarih (1)
- Thumbnail (1)
- Türkçe (1)
- türkçe karakter (1)
- Türksat 4A (1)
- url routing (2)
- utf-8 (1)
- Validation Kontrolleri (3)
- wifi (1)
- WYSIWYG (1)
- WYSIWYG editör (1)
- xml (1)
İşe Yarar Siteler
Blog Archive
-
2014
(91)
- Aralık (1)
- Kasım (4)
- Ekim (9)
- Eylül (5)
- Ağustos (3)
- Nisan (1)
- Mart (20)
-
Şubat
(28)
- asp.net hata ve çözümleri
- Link Değişimi Page Rank Değerini yükseltme
- Bu site bilgisayarınıza zarar verebilir – JavaScri...
- Youtube Videolarından Küçük Resim Çekmek
- Asp.Net de İç İçe Repeater Kullanımı
- Asp.net String İşlemleri
- Asp.net ikili listbox
- Asp.Net Listbox Text ve Value Ekleme
- JQuery Seçiciler ve Filtreler
- ASP.NET Rastgele Sayı ve Harf Üretme
- Ajax Get ve POST methodu ile XMLHTTPRequest
- Bilgisayar Donanımlı Ortamda Fonksiyon ve Graf
- Asp.net ile başka sitenin görüntüsünü alma(Thumbnail)
- Asp.Net ile ekran görüntüsü yakalama(printscreen)
- JavaScript Canvas Image Conversion
- Camera and Video Control with HTML5
- Jquery ile sayfa yükleniyor gifi
- Kısa Flash Notları
- ASP.NET ScriptService
- jquery click event
- Matematikistan.net
- Fraktal ve Fraktal Geometri Nedir
- javascript-hata-bulma-ve-sikistirma-javascript-com...
- Asp.Net Gzip ile Sayfa Sıkıştırma
- Validation hata mesajlarını alertbox ile gösterme
- Asp.net validition karşılaşılan hatalar
- IFrame İçerisindeki Veriye JavaScript ile Erişme
- Asp.Net Canvas Resim Kaydetme
- Ocak (20)
Popular Posts
-
Facebook uygulama geliştirirken bu tarz bir hata aldım. Çözümü : 1) https://developers.facebook.com sayfasından uygulamanın “Settings” ...
-
How to delete, disable and exit Demo Live Unit Retail Mode on the Samsung Galaxy S5 1. The first thing to do is to disable the retail mod...
-
http://www.codeproject.com/Articles/9797/Pager-Control-for-Repeater-DataList-or-an-Enumerab SP.Net projelerinde çokça kullandığımız Repea...
-
Kaynak:http://www.codicode.com/art/upload_and_save_a_canvas_image_to_the_server.aspx In this tutorial I will draw a picture on a Html 5 C...
-
başlat>çalıştır>regedit burdan aşağıdaki değerleri silin; HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\De...
-
Öncelikle http://htmlagilitypack.codeplex.com/ sitesinden Html Agility Pack i indiriyoruz sonra projemizde sağ üstdeki solution ex...
-
Gv-21 T21 android Tv Box Rom İşletim Sistem Kurulumu T301_120_20130111 Kalsörü açtıktan sonra NS115-Burn Tıklayıp çıkan yonerg el...
-
Kaynak:http://bcakir.com/jquery-seciciler-ve-filtreler.html Kullanımı Açıklaması $(“p”) bütün paragrafları seçer $(“div p”) ...
-
✅ 1) Sadece gizli ENTER (LF / ASCII 10) silmek için =YERİNEKOY(TEMİZ(B75321);DAMGA(10);"") ✔ Bu, metnin sonundaki ASCII 10 (sa...
-
Kaynak: http://www.buradayaziyor.com/index.php/2012/07/bu-site-bilgisayariniza-zarar-verebilir/ Burada yanlış giden bir şeyler var We...
© Arif Erzin Bloğu-Kendime Notlar 2013 . Powered by Bootstrap , Blogger templates and RWD Testing Tool

Hiç yorum yok :
Yorum Gönder