1
urbanspacema
jquery admin side, debug problem

Hello fellow developer!
I'm working on a new module (quiet calm are just the beginning) but I need a hand.

In Admin Side,i'm doing a form that inserts a field in a table and I'm doing with jQuery, and now it works. Unfortunately, if active XOOPS debugging the ajax does not work anymore.

This is the code of the page format.php
<?php include 'header.php'; if(isset($_GET['delete'])) { $sql = 'DELETE FROM '.$xoopsDB->prefix('umus_format').' WHERE format_id = '.(int)$_GET['delete']; $result = $xoopsDB->queryF($sql); if(isset($_GET['ajax'])&&$_GET['ajax']==1) exit(); } if ($_REQUEST[fname] != ""){ $fname = htmlspecialchars(trim($_REQUEST['fname'])); $sql_insert = "INSERT INTO ".$xoopsDB->prefix("umus_format")."(format_title) VALUES ('".$fname."')"; $result_insert = $xoopsDB->queryF($sql_insert); $fid = $xoopsDB->getInsertId(); echo $fid; exit(); } xoops_cp_header(); loadModuleAdminMenu(1, ""); //includo js e css include ('../include/library.php'); //per tutti i casi abilito il textsanitizer $myts =& MyTextSanitizer::getInstance(); if (isset($_GET)) { foreach ($_GET as $k => $v) { if(!isset($$k)) $$k = $v; } } if (isset($_POST)) { foreach ($_POST as $k => $v) { if(!isset($$k)) $$k = $v; } } ?> <form id="submit" method="post"> <fieldset style='height:45px;'> <legend>Inserisci nuovo formato</legend> <label for="fname">Formato:</label> <input id="fname" class="text" name="fname" size="20" type="text" /><div class='success'>Formato inserito con successo.</div> <button class="button positive">Aggiungi</button> </fieldset> </form> <?php echo "<table class='stripeMe' id='tablist'> <th colspan='4'>"._MI_UMUS_LISTFORMAT."</th> <tr class='head'><td>"._MI_UMUS_FORMAT_TITLE."</td><td width='150'>"._MI_UMUS_ACTION."</td></tr>"; $sql = 'SELECT * FROM '.$xoopsDB->prefix('umus_format').' ORDER BY format_title '; $result = $xoopsDB->queryF($sql); while($row = mysql_fetch_array($result)) { echo '<tr class="record" id="record-',$row['format_id'],'"> <td><strong>'.$row['format_title'].'</strong></td> <td text-align="center"><a href="?delete='.$row['format_id'].'" class="delete" ><img src="../images/del.png" alt="'._MI_UMUS_DELETE.'" /></a> </td> </tr>'; } echo "</table>"; xoops_cp_footer(); ?>


library.php
le="color: #000000"><?php <link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="../css/umusic.css" /> <script type="text/javascript" src="../library/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="../library/jquery.confirm.js"></script> <script type="text/javascript" src="../library/jquery.mie.js"></script> <script type="text/javascript" src="../library/jquery.color.js"></script>


jquery.mie.js (my script)

le="color: #000000"><?php //cancello un formato $(document).ready(function() { $('a.delete').click(function(e) { e.preventDefault(); //var parent = $(this).parent(); var parent = $(this).parent("td").parent("tr"); { $.ajax({ type: 'get', url: 'format.php', data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''), success: function() { parent.fadeOut(500,function() { parent.remove(); }); } }); } }).confirm(); }); //stripe table $(document).ready(function(){ $('.stripeMe tr').mouseover(function(){ $(this).addClass("over"); }); $('.stripeMe tr').mouseout(function(){ $(this).removeClass("over"); }); $('.stripeMe tr:even').addClass('alt'); }); //creo un nuovo formato $(document).ready(function(){ $('form#submit').submit(function() { // we want to store the values from the form input box, then send via ajax below var fname = $('#fname').attr('value'); if (fname != "") { $.ajax({ type: 'post', dataType: 'text', url: 'format.php', data: 'fname='+ fname, success: function(fid){ $('div.success').fadeIn(1000); $('div.success').fadeOut(3000); $('table#tablist').append("<tr class='record' id='record-"+fid+"' style='background-color:#ff6666; color:#ffffff;'><td><strong>"+fname+"</strong></td><td text-align='center'><a href='?delete="+fid+"' class='delete'><img src='../images/del.png' alt='Delete' /></a></td></tr>"); $('a.delete').click(function(e) { e.preventDefault(); //var parent = $(this).parent(); var parent = $(this).parent("td").parent("tr"); { $.ajax({ type: 'get', url: 'format.php', data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''), success: function() { parent.fadeOut(500,function() { parent.remove(); }); } }); } }).confirm(); } }); } return false; }); });


2
Catzwolf
Re: jquery admin side, debug problem
  • 2009/3/24 1:30

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


It could be that XOOPS JS is conflicting with JQuery. If you can rename your JQuery functions etc. XOOPS uses $ in its js library.

3
trabis
Re: jquery admin side, debug problem
  • 2009/3/24 1:34

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


You can't have any output before an ajax call or it will break it.
Just turn debug off for that page using:
le="color: #000000"><?php error_reporting(0); $xoopsLogger->activated = false;

4
urbanspacema
Re: jquery admin side, debug problem

tnx catz and trabis.
Trabis This code must be placed in my file format.pho right?

5
urbanspacema
Re: jquery admin side, debug problem

Ok, work perfectly...
Unfortunately, so you can use the debugging with ajax ... Perhaps in future versions of XOOPS this thing can be corrected?

6
urbanspacema
Re: jquery admin side, debug problem

another question
in the file format.php i have many $variables that I would go to the javascript file jquery.mie.js for checking errors with cycles of IF.

I tried to assign a variable in the file format.php
$exist = "foo";

and called in javascript with this
var exist = ( '<? php echo "$exist";?>');

But it does not work...

at this time sending from file format.php to js file a variable $fid...

any idea?
tnx a lot
Urban

7
trabis
Re: jquery admin side, debug problem
  • 2009/3/24 13:57

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


I think you have to add a javascript function to set some vars.

Some think like:

var var1 = 0;
var var2 = 0;
function setVars(var1, var2){
this.var1 = var1;
this.var2 = var2;
}

and then use in php file something like

$var1 = 10;
$var2 = 20;
echo'
<script type="text/javascript">
setVars('.$var1.', '.$var2.')
</script>
';

Just a guess :(

It would be easier if you build your javascript inside php and then echo it.

8
urbanspacema
Re: jquery admin side, debug problem

I try your version otherwise I put the js in the php file

Login

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits