1 (edited by avtor-tour 2013-01-18 10:43:56 AM)

Topic: I have a problem

I've a problem. There's some code, it's from example, but it's not working. Fireburg says - uncaught exception: [object Object] on string of number 4
Here's the code
include 'xajax/xajax_core/xajax.inc.php';
$xajax = new xajax();

$xajax->register(XAJAX_FUNCTION, "myFunction");
function myFunction($arg)
{
    // do some stuff based on $arg like query data from a database and
    // put it into a variable like $newContent
        $newContent = "Value of \$arg: ".$arg;
   
    // Instantiate the xajaxResponse object
    $objResponse = new xajaxResponse();
   
    // add a command to the response to assign the innerHTML attribute of
    // the element with id="SomeElementId" to whatever the new content is
    $objResponse->assign("SomeElementId","innerHTML", $newContent);
   
    //return the  xajaxResponse object
    return $objResponse;
}
$xajax->processRequest();
$xajax->printJavascript("xajax");
?>
<div id="SomeElementId"></div>
<input onclick="xajax_myFunction('It worked!');" type="button"/>
P.S. I like your idea to use that great liblrary.

Re: I have a problem

Hello,

What version of xajax are you using and what version of php are you using?

xajax 0.6 needs php 5.3. xajax 0.5 will throw a couple of warning if using php 5.3.

It looks more like the client side is complaining, however.

Have you tried turning on the xajax debugger to see exactly what is going back and forth?

Try moving the printjavascript call into the head tag of your html page.

It may also be necessary to include this after you instance xajax:

$xajax->configure('javascript URI', 'xajax/');

If all of these fail you can post the complete php and html and I'll take a look at it.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: I have a problem

Hi. As always, i'm hurry up smile. I'll try what you've just written. Anyway thanks a lot for your answer.

4 (edited by avtor-tour 2013-01-24 12:29:51 PM)

Re: I have a problem

php 5.3.5

xajax 0.6 beta 1

Framework Kohana with Xajax

I have some problem

I made application/vendor folder and uploaded xajax_core, into this I've renamed file xajax.inc.php to Xajax.php

After uploaded folder public/js/xajax_js

Then I created Controller/Model/Xajax.php file

<?php defined('SYSPATH') or die('No direct script access.');

class Model_Xajax_Xajaxcity extends Model {
               public $_xajax;
               public $_xajax_js;
               
        public function __construct()
        {
          require_once Kohana::find_file('vendor', 'xajax_core/Xajax', 'php');
          $this->_xajax = new Xajax();
         $this->_xajax->register(XAJAX_FUNCTION, array('result', $this, 'result') );
         $this->_xajax->processRequest();
         $this->_xajax->configure('javascript URI', URL::base().'public/js/');
         $this->_xajax_js =  $this->_xajax->printJavaScript(URL::base()."public/js/");
        }
       
        public function result()
        {
         $objResponse = new xajaxResponse();     
         $objResponse->alert("ok");   
        return $objResponse;
        }   
   
}//end class


After That I wrote Controller/City.php

class Controller_City extends Common {
    public $template = 'page';
    protected $cityposition = 'Красноярск';
   
    public function before()
    {
          parent::before();
         
         $xajax = new Model_Xajax_Xajaxcity;
         
         
         
       //this's getting printJavaScript in the Template
         View::bind_global('xajax_js', $xajax->_xajax_js);
       
    }

        public function action_index()
        {
       
        $this->template->title .= '';
        $this->template->center_block = array(View::factory('some.php'));

        }//end of index
In the head of page i see my function

<head>
<script charset="UTF-8" type="text/javascript">
/* <![CDATA[ */
try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
xajax.config.requestURI = "http://tour-touristik.loc/krasnoyarsk/index.html";
xajax.config.statusMessages = false;
xajax.config.waitCursor = true;
xajax.config.version = "xajax 0.5";
xajax.config.defaultMode = "asynchronous";
xajax.config.defaultMethod = "POST";
xajax.config.JavaScriptURI = "/public/js/";
/* ]]> */
</script>
<script charset="UTF-8" src="/public/js/xajax_js/xajax_core.js" type="text/javascript">
Перезагрузите страницу, чтобы получить источник для: http://tour-touristik.loc/public/js/xaj … ax_core.js
</script>
<script charset="UTF-8" type="text/javascript">
/* <![CDATA[ */
window.setTimeout(
function() {
var scriptExists = false;
try { if (xajax.isLoaded) scriptExists = true; }
catch (e) {}
if (!scriptExists) {
alert("Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?\nURL: /public/js/xajax_js/xajax_core.js");
}
}, 2000);
/* ]]> */
</script>
<script charset="UTF-8" type="text/javascript">
/* <![CDATA[ */
xajax_result = function() { return xajax.request( { xjxfun: 'result' }, { parameters: arguments } ); };
/* ]]> */
</script>

But how to get the method? Any ideas, please

Re: I have a problem

In your html you add an event to an element like a button input:

<input type="button" value="Click Me" onclick="xajax_result()"/>

The onclick calls your function on the server.

The js defines your function with the default xajax prefix. This is a result of having registered it in the php code.

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: I have a problem

Hi, I did it, just forgot to write, but nothing happens

7 (edited by avtor-tour 2013-01-24 10:42:20 PM)

Re: I have a problem

It's turn out, it's because i've used the helpers of kohana, but need to be write simple html. it's my fault smile, anyways thanks a lot for your answer

Re: I have a problem

Your welcome. I am a CI fan myself...

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.