宗像タウン情報 キラリ

お問い合わせ

 

  ホーム >> RSSセンター >> Solving ajax giving cross-domain error or responding empty

RSSセンター

  メイン  |  簡易ヘッドライン  

link XOOPS.org XOOPS.org (2024/11/23 5:11:46)

feed Solving ajax giving cross-domain error or responding empty (2012/3/10 3:23:20)
When assigning XOOPS_URL to a java_script variable in eighter preloads or specific pages.

Most often the browser will deny your request and return only an empty respond. But not give error. This can be seen in FireBug's console when the requests is returning code "200 OK" but text is in red color = empty result. Very annoying

The problem is between Xoops Cookie and browser. I noticed this when being logged in to a xoops page and closing the page without logging out. When re-opened the ajax running in my preloads (in this case XIM and Smallworld) was denying sending messages or posting to the wall.

Also this is a problem if you log out from http://domain.com and open http://www.domain.com .

There are as I see this 2 solutions.

1) Everytime you finish browsing do log out.

Another solution is to define the java_script var used in ajax requests according to actual browser adress.

Add a function to your page (if you add to include/functions.php remember to include this page in preloads or the page your working on)

/**
     * @Get url of smallworld
     * @returns string
     */ 
    
function  smallworld_getHostRequest () 
    {
        
$protocol  strpos ( strtolower ( $_SERVER [ 'SERVER_PROTOCOL' ]), 'https' ) ===  FALSE  'http'  'https' ;
        
$host      $_SERVER [ 'HTTP_HOST' ];
        
$script    $_SERVER [ 'SCRIPT_NAME' ];
        
$params    $_SERVER [ 'QUERY_STRING' ];
        
$currentUrl  $protocol  '://'  $host ;
        return 
$currentUrl ;
    }


In your page reset the var like this
// Check if request url is with www or without
        
global  $xoTheme ;
        
$urltest  smallworld_getHostRequest ();
        
$xoops_url  XOOPS_URL ;
        if (!
strstr ( $urltest 'www.' )) {
            
$xoops_url  str_replace 'www.' '' $xoops_url  );
        }

        
$script  "var smallworld_url = '"  $xoops_url  "/modules/smallworld/"  "';n" ;
        
$xoTheme -> addScript ( '' , '' , $script );


The var smallworld_url will now be according to your browser adress and this way not result in ajax cross-browser error.


execution time : 0.019 sec

↑ PAGE TOP