JAVASCRIPT 10
Ajax.js Guest on 4th August 2020 05:16:18 PM
  1. // Ajax javascript file
  2.  
  3. // Setup variables for browser checking
  4. var browser = navigator.appName;
  5. var isopera = false;
  6. if ( navigator.userAgent.indexOf( 'Opera' ) >= 0 ) {
  7.   isopera = true;
  8. }
  9. var ismac = false;
  10. if ( navigator.platform.indexOf( 'Macintosh' ) >= 0 ) {
  11.   ismac = true;
  12. }
  13. var isie = false;
  14. if ( browser.indexOf( 'Explorer' ) >= 0 ) {
  15.   isie = true;
  16. }
  17.  
  18. // Returns an AJAX request object
  19. function makeObject(){
  20.   var x;
  21.   if(browser == "Microsoft Internet Explorer" && !isopera && !ismac ){
  22.     x = new ActiveXObject("Microsoft.XMLHTTP");
  23.   }else{
  24.     x = new XMLHttpRequest();
  25.   }
  26.   return x;
  27. }
  28.  
  29.  
  30. // Create the AJAX request object.
  31. xreq = makeObject();
  32.  
  33. // A method to call our ajax server side script using get method.
  34. // First argument is the task to tell ajax to run, second arguments is
  35. // a string with get arguments to send with the script.
  36. function ajaxGet(task, args, func){
  37.   xreq.open('get', 'index2.php?option=com_jambook&task='+task+args);
  38.   xreq.onreadystatechange = func;
  39.   xreq.send('');
  40. }
  41.  
  42. // A function to handle the data returned by the ajax server side script.
  43. // Results are printed in the html element named 'ajax_div'
  44. function parseData(){
  45.   if(xreq.readyState == 1){
  46.     document.getElementById('ajax_div').innerHTML = 'Handling request...';
  47.   }
  48.   if(xreq.readyState == 4){
  49.     var result = xreq.responseText;
  50.     document.getElementById('ajax_div').innerHTML = result;
  51.   }
  52. }
  53.  
  54. // A function that does nothing
  55. function noopFunc() {
  56.   return true;
  57. }
  58.  
  59. // Save screen resolution
  60. function saveResolution( func ) {
  61.   var sres = checkResolution();
  62.   var wdim = checkWindowDimensions();
  63.   ajaxGet('savescreenresolution', '&sres=' + sres + '&wdim=' + wdim, func);
  64. }
  65.  
  66. // Save the screen resolution for this IP:
  67. //saveResolution( noopFunc );
  68.  
  69. ajaxitemid = 0;
  70. function listItemAjax( id, task ) {
  71.     var f = document.adminForm;
  72.     cb = eval( 'f.' + id );
  73.     if (cb) {
  74.         for (i = 0; true; i++) {
  75.             cbx = eval('f.cb'+i);
  76.             if (!cbx) break;
  77.             cbx.checked = false;
  78.         } // for
  79.         cb.checked = true;
  80.         f.boxchecked.value = 1;
  81.         ajaxitemid = cb.value;
  82.         if ( task == 'pubunpub' && xreq ) {
  83.             itemtask = eval( 'f.pub' + ajaxitemid );
  84.             ajaxGet(itemtask.value, '&nohtml=1&pid[0]='+cb.value, switchImageAjax );
  85.             if ( itemtask.value == 'publish' )
  86.                 itemtask.value = 'unpublish';
  87.             else
  88.                 itemtask.value = 'publish';
  89.         } else {
  90.             submitbutton(task);
  91.         }
  92.     }
  93.     return false;
  94. }
  95.  
  96. function switchImageAjax( ) {
  97.     if ( xreq.readyState == 4 ) {
  98.         var result = xreq.responseText;
  99.         document.getElementById( 'itemimg' + ajaxitemid ).src = 'images/'+result+'.png';
  100.         //alert( 'itemimg'+ajaxitemid + ' ' + 'images/'+ result +'.png' );
  101.         //MM_swapImage( 'itemimg'+ajaxitemid, '', 'images/'+ result +'.png' );
  102.     }
  103. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.