Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: XAJAX - kłopot z "$this->..." w metodzie klasy
Forum PHP.pl > Forum > XML, AJAX > AJAX
lewiusz
Tworzę klasę, metodę klasy rejestruję w XAJAX, wszystko działa dopóki nie użyję w zarejestrowanej metodzie "$this->..."
Poniżej standardowy przykład działania XAJAX'a, w którym wstawiłem klasę "test".
Po naciśnięciu CLICK ME generowany jest błąd:
"Error: the XML response that was returned from the server is invalid. Recived:"

  1. <?php
  2. // helloworld.php demonstrates a very basic xajax implementation
  3. // using xajax version 0.1 beta4
  4. // <a href="http://xajax.sourceforge.net" target="_blank">http://xajax.sourceforge.net</a>
  5.  
  6. require ('xajax/xajax.inc.php');
  7.  
  8. class test {
  9. public $tekst = 'byleco';
  10.  
  11. function helloWorld($isCaps)
  12. {
  13. if ($isCaps)
  14. $text = $this->tekst;
  15. else
  16. $text = 'Hello World!';
  17.  
  18. $objResponse = new xajaxResponse();
  19. $objResponse->addAssign('div1','innerHTML',$text);
  20. return $objResponse;
  21. }
  22. }
  23.  
  24. // Instantiate the xajax object. No parameters defaults requestURI to this page, method to POST, and debug to off
  25. $xajax = new xajax(); 
  26.  
  27. //$xajax->debugOn(); // Uncomment this line to turn debugging on
  28.  
  29. // Specify the PHP functions to wrap. The JavaScript wrappers will be named xajax_
    functionname
  30. $xajax->registerFunction(array('helloWorld','test','helloWorld'));
  31.  
  32. // Process any requests. Because our requestURI is the same as our html page,
  33. // this must be called before any headers or HTML output have been sent
  34. $xajax->processRequests();
  35. ?>
  36. <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
  37. <html>
  38. <head>
  39. <title>xajax example</title>
  40. <?php $xajax->printJavascript('xajax/'); // output the xajax javascript. This must be called between the head tags ?>
  41. </head>
  42. <body>
  43. <div id='div1' name='div1'> </div>
  44. <?php $n = new test; echo $n->tekst; ?>
  45. <br/>
  46.  
  47. <button onclick='xajax_helloWorld(0)' >Click Me</button>
  48. <button onclick='xajax_helloWorld(1)' >CLICK ME</button>
  49. <script type='text/javascript'>
  50. xajax_helloWorld(0); // call the helloWorld function to populate the div on load
  51. </script>
  52. </body>
  53. </html>


Bardzo proszę o pomoc w rozwikłaniu tego problemu.
kaniagandzowski
  1. <?php
  2. $xajax->registerFunction(array('helloWorld','test','helloWorld'));
  3. ?>


to zamien na
  1. <?php
  2. $xajax->registerFunction(array('helloWorld',$this,'helloWorld'));
  3. ?>
vego007
Odgrzeję kotleta bo mam podobny problem.

To jest mój kod php używany do generowania drugiej listy na podstawie wyboru z pierwszej listy

  1. <?php
  2. function extended_delete_by_name()
  3.    {
  4.        
  5.        
  6.        // XAJAX
  7.        $this->_load_xajax();
  8.        // targi
  9.        $this->data['province_dropdownlist'] = $this->build_province_dropdownlist();
  10.        // wrzutki
  11.        $this->data['div_extended_name'] = '';
  12.        // load views
  13.        $this->data['content'] = $this->load->view('extended/extended_delete_form', $this->data, true);
  14.  
  15.        //$query = $this->Extended_db->get_extended_names();
  16.         $this->response['content'] = $this->load->view(
  17.                'extended/extended_delete_form',
  18.                null,
  19.                True
  20.                );
  21.        $this->load->view('index', $this->response);
  22.        
  23.    }
  24.        
  25.    
  26.  
  27.    function province_onchange($province)
  28.    {
  29.           $objResponse = new xajaxResponse();        
  30.  
  31.        if ($province != '0')
  32.        {
  33.            $output = $this->build_extended_dropdownlist($province);
  34.            $objResponse->addAssign("div_extended_name", "innerHTML", $output);
  35.        }
  36.        else
  37.        {
  38.            $objResponse->addAssign("div_extended_name", "innerHTML", "");
  39.        }
  40.        
  41.        return $objResponse;
  42.    }
  43.  
  44.    
  45.    function build_province_dropdownlist()
  46.    {
  47.        
  48.        $output = "<select id='province' name='province' style='width:200px;' onchange='xajax_province_onchange(this[this.selectedIndex].value);'>";
  49.        
  50.        $output .= $this->new_option('Wybierz region',  '', 0);
  51.  
  52.        $provinces = $this->province;
  53.  
  54.        foreach ($provinces as $key => $row)
  55.        {
  56.            $output .= $this->new_option($row, $row);
  57.        }
  58.  
  59.        $output .= "</select>";
  60.  
  61.        return ($output);
  62.    }
  63.    
  64.    function build_extended_dropdownlist()
  65.    {
  66.        $output = "<select id='currency_name' name='currency_name' style='width:200px;' >";
  67.        
  68.        //$output .= $this->new_option('Wybierz walutę',  '', 0);
  69.        
  70.        
  71.        $names = $this->Extended_db->get_extended_names();
  72.  
  73.        foreach($names as $key => $row)
  74.        {
  75.            $output .= $this->new_option($row, $key);
  76.        }
  77.        
  78.        //$output .= '<option value="siema">Siema</option>';
  79.        
  80.        $output .= "</select>";
  81.  
  82.        return ($output);
  83.    }
  84.    
  85.  
  86.    
  87.    function new_option($text, $value)
  88.    {
  89.        $output = "<option value=\"" . $value . "\"";
  90.  
  91.        $output .= ">" . $text . "</option>";
  92.    
  93.       return ($output);
  94.    }
  95. ?>


W odpowiedzi dostaję coś takiego

  1. <localhost>
  2.  
  3.  
  4.  
  5. Error: the XML response that was returned from the server is invalid.
  6.  
  7. Received:
  8.  
  9. SELECT DISTINCT `extended_name`
  10.  
  11. FROM (`extended`)<br /><br /><?xml version="1.0" encoding="utf-8" ?><xjx><cmd n="as" t="div_extended_name" p="innerHTML"><![CDATA[<select id='currency_name' name='currency_name' style='width:200px;' ><option value="0">Test 1</option><option value="1">Test_2</option><option value="2">TEST_IE</option><option value="3">Test_cztery 1</option><option value="4">Test5 10-11</option><option value="5">Dlugi_test_sześć 12</option></select>]]></cmd></xjx>


Skrypt generuje się poprawnie pod warunkiem, że sam stworzę sobie tablicę i nie użyję funkcji pobierania danych z bazy, bez względu na to czy używam tej funkcji do czegoś czy nie. Po zakomentowaniu $names = $this->Extended_db->get_extended_names(); i podstawieniu np $this->province do foreach wszystko działa jak należy. Używam Code igniter + Xajax + wamp serwer. Czy to może być problem kodowania? Z góry dziękuję za pomoc
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.