Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //01) Обычный синхронный ajax get запрос
- $.ajax({
- type: "GET",
- url: "/path/path/?promo="+promo+"&code="+code,
- cache: false,
- success: function(html){
- $("#chooseAdd div.content").html(html);
- }
- });
- //02) Обычный синхроный ajax post запрос
- $.post('/path/path/',
- { itemadd : form['itemadd'].value, submitform : form['submitform'].value},
- function(html){
- $("#chooseAdd div.content").html(html);
- }, "html");
- //02.2) Обычный синхроный ajax post запрос 2
- $.ajax({
- type: "POST",
- url: '/path/path/',
- cache: false,
- data: { itemadd : form['itemadd'].value, submitform : form['submitform'].value},
- dataType: "html",
- success: function(html) {
- $("#chosseAddForm").html(html);
- return false;
- }
- });
- //03) Ассинхронные запросы
- //необходимые функции
- //01)
- function getRequestStateText(code) {
- switch (code) {
- case 0: return "Uninitialized."; break;
- case 1: return "Loading..."; break;
- case 2: return "Loaded."; break;
- case 3: return "Interactive..."; break;
- case 4: return "Complete."; break;
- }
- }
- //02)
- function processRequestChange() {
- var gg = getRequestStateText(request.readyState);
- // если выполнен
- if (request.readyState == 4) {
- // если успешно
- if (request.status == 200) {
- $("#chooseAdd div.content").html(request.responseText);
- } else {
- alert("Не удалось получить данные:n" + request.statusText);
- }
- }
- // иначе, если идет загрузка или в процессе - показываем слой "Загружаются данные"
- else if (request.readyState == 3 || request.readyState == 1) {
- }
- }
- //03) для кроссбраузерности
- function getXmlHttp(){
- var xmlhttp;
- try {
- xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- try {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (E) {
- xmlhttp = false;
- }
- }
- if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
- xmlhttp = new XMLHttpRequest();
- }
- return xmlhttp;
- }
- //Ассинхронный get запрос
- var request = getXmlHttp();
- request.mozBackgroundRequest = true; //for mozzila
- request.onreadystatechange = processRequestChange;
- request.open('GET', "/path/path/?promo="+promo+"&code="+code, true); // готовим сам запрос
- request.send(null); // посылаем запрос методом send
- var timeout = setTimeout( function(){ request.abort(); }, 10000);
- //Ассинхронный post запрос
- var params = 'itemadd=' + encodeURIComponent(form['itemadd'].value)
- + '&submitform=' + encodeURIComponent(form['submitform'].value);
- var request = getXmlHttp();
- request.mozBackgroundRequest = true;
- request.onreadystatechange = processRequestChange;
- request.open('POST', "/path/path/", true); // готовим сам запрос
- request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //устанавливаем заголовок
- request.send(params); // посылаем запрос методом send
- var timeout = setTimeout( function(){ request.abort(); }, 10000);
Advertisement
Add Comment
Please, Sign In to add comment