PDA

View Full Version : سوال آجاکسی



paksar
شنبه 12 مرداد 1387, 11:09 صبح
سلام

من این کد رو برای لود کردن صفحه ای با متد GET استفاده می کنم از اونجا که لود شدن ممکنه یکم طول بکشه و کاربر نفهمه میخواستم
یه لودینگ براش بزارم در همین خصوص از دوستانی که با آجاکس کار کردن و میدونن، کد لودینگ این اسکریپت رو بزارن.



var http_request = false;
function makeRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
//Start Show Your Image Or Comment
http_request.onreadystatechange = alertContents;
http_request.open('GET', url + parameters, true);
http_request.send(null);
}

function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
//End Show Your Image Or Comment
result = http_request.responseText;
document.getElementById('log_res').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
}


می بخشید من یه بار این تاپیکو جای دیگه ای ایجاد کردم اما مثل اینکه مثل اینجا با حال نیستن.
آقای یعقوبیان احتمالا شما میتونین مشکل منو حل کنید.

ممنون

Bahram0110
شنبه 12 مرداد 1387, 12:13 عصر
سلام
یه DIV برای لودینگ بذار و display رو none بزن
وقتی خواستی صفحه رو لود کنی display رو به "" تغییر بده