H.E. Pennypacker
Newbie
Registered: 2006-11-13
Posts: 6
I am using Zend Framework 0.20 and Xajax 0.5. I am having issues with a simple hello world example. I just get the generic "The XML response from the server was invalid.." message so it's not helping at all. I have a very simple hello world.
Here is my controller code:
Code: PHP
<?php class HelloWorldController extends Zend_Controller_Action { function indexAction() { $xajax = new xajax(); $xajax->registerFunction(array("doAlert", $this, "doAlert")); $xajax->processRequest(); $view = Zend::registry("view"); $view->title = "Hello World"; $view->xajaxJs = $xajax->getJavascript("/js/", "xajax.js"); echo $view->render("HelloWorld.php"); } function noRouteAction() { echo "No Route!"; } function doAlert() { $objResponse = new xajaxResponse(); $objResponse->alert("Whaaaaaaaa"); return $objResponse; } } ?>
|
Here is the HTML file (HelloWorld.php):
Code: PHP
<html> <head> <?= $this->xajaxJs; ?> <title><?= $this->escape($this->title); ?></title> <link rel="stylesheet" type="text/css" href="/css/jog.css" /> </head> <body> <div id="content"> <h1><?= $this->escape($this->title); ?></h1> <input type="button" value="Execute Xajax Alert" onClick="xajax_doAlert();" /> </div> </body> </html>
|
And here is a view source of the rendered html file, all looks good:
Code: PHP
<html> <head> <script type="text/javascript"></script> <script type="text/javascript" src="/js/xajax.js"></script> <script type="text/javascript"></script> <title>Hello World</title> <link rel="stylesheet" type="text/css" href="/css/jog.css" /> </head> <body> <div id="content"> <h1>Hello World</h1> <input type="button" value="Execute Xajax Alert" onClick="xajax_doAlert();" /> </div> </body> </html>
|
Finally, a print_r of $_SERVER just in case there is some issue with mod_rewrite and the request URI:
Code: PHP
[REDIRECT_STATUS] => 200 [HTTP_HOST] => 127.0.0.1 [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0 [HTTP_ACCEPT] => application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.7,es-pe;q=0.3 [HTTP_ACCEPT_ENCODING] => gzip,deflate [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7 [HTTP_KEEP_ALIVE] => 300 [HTTP_CONNECTION] => keep-alive [HTTP_CACHE_CONTROL] => max-age=0 [PATH] => c:program filesimagemagick-6.3.0-q16;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:Program FilesATI TechnologiesATI Control Panel;C:Program FilesQuickTimeQTSystem [SystemRoot] => C:WINDOWS [COMSPEC] => C:WINDOWSsystem32cmd.exe [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH [WINDIR] => C:WINDOWS [SERVER_SIGNATURE] => <address>Apache/2.0.59 (Win32) PHP/5.1.6 Server at 127.0.0.1 Port 80</address> [SERVER_SOFTWARE] => Apache/2.0.59 (Win32) PHP/5.1.6 [SERVER_NAME] => 127.0.0.1 [SERVER_ADDR] => 127.0.0.1 [SERVER_PORT] => 80 [REMOTE_ADDR] => 127.0.0.1 [DOCUMENT_ROOT] => C:/wamp/www [SERVER_ADMIN] => webmaster@localhost [SCRIPT_FILENAME] => C:/wamp/www/index.php [REMOTE_PORT] => 4930 [REDIRECT_URL] => /HelloWorld [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /HelloWorld [SCRIPT_NAME] => /index.php [PHP_SELF] => /index.php [REQUEST_TIME] => 1164746605 [argv] => Array ( ) [argc] => 0
|
I'm just running this off a standard php 5.1.6 wamp installation. I've tried changing the URI on the xajax instantiation but nothing seems to get this working. Please, someone help!
CrazyLegz
Newbie
Registered: 2007-02-28
Posts: 3
Hi, I had the same problem and found a solution.
嘿,我和你有遇到同样的问题并且照的了解决方法。
I'm using Zend Framework 0.8.0 and xajax 0.2.4
我使用的是Zend Framework 0.8.0 和 xajax 0.2.4
After examening processRequests() method in the xajax class I found out that processRequests is calling the getRequestMode method. This method returned -1 wich means $_POST["xajax"] and $_GET["xajax"] are empty.
If getRequestMode returns -1 it exits before is has done something at all. So this means your Ajax call isn't processed.
In my case this was very logical. In my index.php bootstrap file I had the following two lines.
Zend::register("post", new Zend_Filter_Input($_POST));
Zend::register("get", new Zend_Filter_Input($_GET));
The $_POST and $_GET arrays are set to NULL by Zend_Filter_Input.
So $_POST["xajax"] will never get to processRequests of the xajax class.
You can resolve this by changing the two lines to the following two lines:
Zend::register("post", new Zend_Filter_Input($_POST, false));
Zend::register("get", new Zend_Filter_Input($_GET, false));
In this way the $_POST and $_GET arrays are left intact.
CtC
Administrator
From: Ohio, USA
Registered: 2006-07-14
Posts: 1331
Website
Thanks for the post! I've added this to the tips and tricks section of the wiki.
// Joe
阅读(2022) | 评论(0) | 转发(0) |