كائن XMLHttpRequest _
باستخدام كائن XMLHttpRequest ، يمكنك تحديث أجزاء من صفحة الويب ، دون إعادة تحميل الصفحة بأكملها.
جربها بنفسك - أمثلة
قم بإنشاء XMLHttpRequest بسيط واسترداد البيانات من ملف TXT.
استرداد معلومات الرأس لمورد (ملف).
استرجع معلومات رأس محددة لمورد (ملف).
كيف يمكن لصفحة ويب الاتصال بخادم ويب بينما يقوم المستخدم بكتابة الأحرف في حقل الإدخال.
كيف يمكن لصفحة ويب جلب معلومات من قاعدة بيانات باستخدام كائن XMLHttpRequest.
قم بإنشاء XMLHttpRequest لاسترداد البيانات من ملف XML وعرض البيانات في جدول HTML.
كائن XMLHttpRequest
يتم استخدام كائن XMLHttpRequest لتبادل البيانات مع خادم خلف الكواليس.
كائن XMLHttpRequest هو حلم المطورين ، لأنه يمكنك:
- تحديث صفحة الويب دون إعادة تحميل الصفحة
- اطلب البيانات من الخادم بعد تحميل الصفحة
- تلقي البيانات من الخادم بعد تحميل الصفحة
- إرسال البيانات إلى خادم في الخلفية
أساليب كائن XMLHttpRequest
Method | Description |
---|---|
abort() | Cancels the current request |
getAllResponseHeaders() | Returns header information |
getResponseHeader() | Returns specific header information |
open(method,url,async,uname,pswd) | Specifies the type of request, the URL, if the request should be handled asynchronously or not, and other optional attributes of a request
method: the type of request: GET or POST url: the location of the file on the server async: true (asynchronous) or false (synchronous) |
send(string) | send(string) Sends the request off to the server. string: Only used for POST requests |
setRequestHeader() | Adds a label/value pair to the header to be sent |
خصائص كائن XMLHttpRequest
Property | Description |
---|---|
onreadystatechange | Stores a function (or the name of a function) to be called automatically each time the readyState property changes |
readyState | Holds the status of the XMLHttpRequest. Changes from 0 to 4: 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready |
responseText | Returns the response data as a string |
responseXML | Returns the response data as XML data |
status | Returns the status-number (e.g. "404" for "Not Found" or "200" for "OK") |
statusText | Returns the status-text (e.g. "Not Found" or "OK") |