Topic: error with Javascript component

Im getting this weird error:

Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?
URL: xajax_js/xajax_js/xajax_js/xajax_core.js

This is my code:

<?php
session_start(); // start up your PHP session! 
require ('xajax_core/xajax.inc.php');
$xajax = new xajax();
$xajax->configure('debug','true');
$xajax->configure('javascript URI', 'xajax_js/');

I have tried putting xajax outside site directory, inside its own xajax directory, anything, I always get a similar error. What I am doing wrong here?

Re: error with Javascript component

Hi,

I keep the xajax stuff in its own folder.

Then

session_start(); // start up your PHP session! 
require ('xajax/xajax_core/xajax.inc.php');
$xajax = new xajax();
$xajax->configure('debug','true');
$xajax->configure('javascript URI', 'xajax/');
If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: error with Javascript component

Same error:

Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?
URL: xajax/xajax_js/xajax_js/xajax_core.js

Re: error with Javascript component

OK. Could you post the offending page's code?

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

Re: error with Javascript component

<?php
session_start(); // start up your PHP session! 
require ('xajax/xajax_core/xajax.inc.php');
$xajax = new xajax();
$xajax->configure('debug','true');
$xajax->configure('javascript URI', 'xajax/');

require 'config.inc.php';
$db = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno($db)) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
 };
 
 
function processCheckbox($id,$checked)
{
    $resp=new xajaxResponse();
    //Here's where you would handle the database update.
    if ($checked) {
        $code = rand(10000,99999);
        $db->query("UPDATE users SET active=$code WHERE id=$id");
    } else {
        $db->query("UPDATE users SET active=0 WHERE id=$id");
    }
    $resp->assign("values","innerHTML" ,"Values: Id: $id  Checked: $checked");    
    return $resp;
}

 $xajax->register(XAJAX_FUNCTION, 'processCheckbox');
 $xajax->processRequest();
 
 //get config
 $q = $db->query("SELECT * FROM config;");
 $conf = $q->fetch_assoc(); 
 echo "<!DOCTYPE HTML>\n";

 echo '<meta charset="UTF-8">';
  
 echo "<title>".$conf["sitename"]."- Site info</title>\n";
  
 echo '<script type="text/javascript" src="js/jquery-1.10.2.js"></script>';
 $xajax->printJavascript();
 ?>
 <script>
    /*
  This function receives the checkbox object,
  extracts it id and checked state and sends them
  to the registered function.
    */
 function handleCheckbox(c)
{
  id = c.id; //The id is the state name
  ck = (c.checked) ? 'true' : 'false'; //This determines if the checkbox is checked 
  xajax_processCheckbox(id,ck); //Call the server function
}
</script>
 
 <?php
 

 echo '<link rel="stylesheet" type="text/css" href="styles.css" />';

 echo '<div id="container" style="border: none; height: 100%; position: absolute; top: 2%; left: 5%; width: 90%">'; //container
 include 'head.php';

 echo '<div class="content">';
 include 'admin-panel.php'; 
if (!isset($_GET['c'])) { //we received no parameter, abort
 echo '<script type="text/javascript">';
 echo '    window.location="index.php";';
 echo '</script>';
}
$id = $_GET['c'];
$q = $db->query("SELECT * FROM users WHERE id=$id;");
$r = $q->fetch_assoc();
echo '<a href="index.php" name="Home">Home</a> >> Viewing profile: <br>';

echo '<div style="background: #3399FF;; display: block; width: 550px; float: left; overflow: hidden; padding: 2px">';
echo '<div style=" display: block; width: 120px; float: left">';
echo '<img src="'.$conf["uploads"].'avatars/'.$r["avatar"].'" width="120" height="150">';
echo "</div>\n";
echo "<h1>".$r["name"]."</h1>\n";
echo 'Member since: '.$r["register"]."<br>";
echo '<p>Rating: '.$r["rank"]; 
echo '<br id="values">Active: ';
if ($r["active"]==0) {
    echo '<input type="checkbox" id="'.$r["id"].'" checked  onclick="handleCheckbox(this)">';
    } else {
    echo '<input type="checkbox" id="'.$r["id"].'"onclick="handleCheckbox(this)">';    }
echo '<br>Privilege group: ';
echo '<select name="priv">';
echo '<option value="0">Admin</option>';
echo '<option value="1">Users</option>';
echo '<option value="2">Premium users</option>';
echo "</select>\n";
echo '<br><a href="contact.php">Contact this user</a><br><br>';
echo "About:<br>\n";
echo $r["about"];

echo "</div>\n";
 echo  "</div>\n"; //content
 echo "</div>\n"; //container
?>

Re: error with Javascript component

Well, I copied your code and - I hate to say it - I do not get the error on my system.

What version of xajax are you using?
What version of php are you using?
Are there any messages in you server log?

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

Re: error with Javascript component

I got Xajax from github, the file says Xajax-master.zip, no version, php is 5.5 (Fedora 19), I found this on the log:

[Tue Oct 22 13:36:29.435199 2013] [:error] [pid 3050] [client 200.55.150.179:33249] PHP Warning:  file_put_contents(/var/www/html/class/xajax/xajax_js/deferred/db4e7ab1b9c71c70cb24aa152b4f35ad.js): failed to open stream: No such file or directory in /var/www/html/class/xajax/xajax_core/xajaxPluginManager.inc.php on line 588, referer: http://200.55.150.179/class/user-panel.php

Re: error with Javascript component

Aha! I have seen this before...

Create a subfolder in the xajax_js folder named "deferred." I think you are using version 0.6 and it needs that folder.

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

Re: error with Javascript component

Yep! That solved the problem, thanks a lot!