Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
server script not returning response text AJAX
Old 09-01-2008, 02:47 PM server script not returning response text AJAX
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
This script is returning an empty xmlHttp.responseText? ? ?
Code:
 
<?php
$conn = mysql_connect("xxx","xxx","xxx"); 
mysql_select_db("xxx",$conn);
$Title = $_GET["Title"];
if($Title)
 {
 $SQL = "Insert Into Categories Values (NULL,'".$Title."','Enabled')";
 mysql_query($SQL);
 }
$SQL = "Select * From Categories";
$result = mysql_query($SQL);
while($row = mysql_fetch_array($result))
 {
echo "    <tr>"; 
echo " <td><div class = 'style8' align = 'left'>{$row['Title']}</div></td>";
echo " <td><div class = 'style8' align = 'right'>{$row['Enable']}</div></td>";
echo "   </tr>";
 }
?>
I have even tried eliminating the databse operations and just placing the statement

Code:
 
echo "hello";
This is the client script:

Code:
 
function NewCat (Elem)
{
Init(); //creates xmlhttprequest object
var Input = prompt("Please enter title for new category");
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById(Elem).innerHTML = xmlHttp.responseText;
}
}
ReqStr = "NewCat.php?Title=" + Input;
xmlHttp.open("Get",ReqStr,true);
xmlHttp.send(null);
}

Last edited by Sleeping Troll; 09-01-2008 at 02:56 PM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-01-2008, 03:51 PM Re: server script not returning response text AJAX
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
The script isn't complete.

You need to give us all the code ie a function called Init() is called within NewCat(). Is this available to the script?

Also I don't see where/how the ajax function NewCat() is being executed.

Last edited by maxxximus; 09-01-2008 at 03:54 PM..
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 09-01-2008, 07:56 PM Re: server script not returning response text AJAX
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
The Init() function creates the xmlhttprequest object. NewCat is being called by an "onclick" event. I have tested the code and the request is being sent and the server is responding with "", curiously enough the database is not being updated... However when I simplify server script to:

<?php
echo "hello";
?>



I still get "" for response.
**** that's one tough bug! I have sprayed the crap out of it and it has not even slowed down! But the bug I have described is making my head hurt!!!

Last edited by Sleeping Troll; 09-01-2008 at 07:59 PM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 09-01-2008, 08:21 PM Re: server script not returning response text AJAX
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
sending spaces in a GET request will fail as the first space will delimit the URI string. You HAVE to encode the URI.

ReqStr = "NewCat.php?Title=" + encodeURI(Input)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-01-2008, 08:37 PM Re: server script not returning response text AJAX
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Will check that Chris, but I don't think I have sent spaces, however it could be an issue later.
thx.

Nope same thing...

Last edited by Sleeping Troll; 09-01-2008 at 08:39 PM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 09-01-2008, 08:38 PM Re: server script not returning response text AJAX
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Try this script and see what happens.

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/JavaScript">
function ajaxFunction()
{
 
      
      var b = "include"; 
     var a = prompt("Please enter title for new category");
     a= "NewCat.php?Title=" + a;

 
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
          
          if(xmlHttp.readyState==1)
        {
       document.getElementById(b).innerHTML='<div align="center"><p>Loading, please wait ...</p></div>';
        }
      if(xmlHttp.readyState==4)
        {
       document.getElementById(b).innerHTML=xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET",a,true);
    xmlHttp.send(null);
  }


</script>
</head>

<body ><form action="" method="get"><input name="title" type="button" id="title" onclick="ajaxFunction()" value="title" />
</form>
<div id="include"></div>
</body>
</html>
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 09-02-2008, 05:12 AM Re: server script not returning response text AJAX
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Thx for the magnanimous effort, maxxximus. Somehow my NewCat.php got wiped out, but that is a mixed blessing. Your script works with a simple echo script server side, mine does not. So at least I know problem is client side. One thing I noticed about myself as a programmer, I tend to be a bull in a china shop when it comes to reserved words. I changed "Input" to "Title" and my database updates. However the page is not updating, I know problem is clent side. (thx again maxxximus) But I really haven't a clue what it is! So here is the complete client side script. I have inspected the DOM and indeed the new content is not present.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Default</title> 
<?php
$conn = mysql_connect("xxx","xxx","xxx"); 
mysql_select_db("xxx",$conn);
?>
<script type="text/javascript">
<!--
var xmlHttp;
function Init()
 {
   try
     {  // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
     }
     catch (e)
       {  // Internet Explorer
        try
          {
          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }
           catch (e)
            {
            try
               {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
               }
               catch (e)
                 {
                  alert("Your browser does not support AJAX!");
                }
          }
       }
 }
 
function NewCat(Elem)
 {
  Init();
   var Title = prompt("Please enter title for new category");
  xmlHttp.onreadystatechange=function()
     {
    if(xmlHttp.readyState==4)
     {
     document.getElementById(Elem).innerHTML = xmlHttp.responseText;
     }
   }
  ReqStr = "NewCat.php?Title=" + encodeURI(Title);
  xmlHttp.open("Get",ReqStr,true);
  xmlHttp.send(null);
 }
//-->
</script>
<style type="text/css">
<!--
.style1 {
 font-family: "GrilledCheese BTN";
 font-size: large;
}
.style2 {
 font-family: "GrilledCheese BTN";
 font-size: x-small;
}
.style3 {font-family: "GrilledCheese BTN"}
a:hover {
 font-family: "GrilledCheese BTN";
 font-size: larger;
 color: #000000;
}
body {
 background-color: #FDF993;
}
a:link {
 color: #000000;
 text-decoration: none;
}
dl, dt, dd, ul, li {
margin: 0;
padding: 0;
list-style-type: none;
}
.style8 {font-family: "GrilledCheese BTN"; font-size: small; }
a:visited {
 color: #000000;
}
a:active {
 color: #000000;
}
-->
</style>
<body>
<table width="100%" border="0">
 <tr>
          <!-- Bumper -->
  <td>&nbsp;</td>
          <!-- Bumper -->
          <!-- Login Panel Start -->
  <td width="120" align="center" class="style3" id = "Message">
  <div align="center"><?php echo $Msg ?></div></td>
          <!-- Login Panel End -->
          <!-- Bumper -->
  <td>&nbsp;</td>
          <!-- Bumper -->
          <!-- Banner Panel Start -->
  <td id = "Banner" align="center" height="120">
   <div><img src="../Images/Bnnr.png" width="700" height="91"></div>
  </td>
          <!-- Banner Panel End -->
          <!-- Bumper -->
 
  <td>&nbsp;</td>
 
          <!-- Bumper -->
          <!-- Navigation Panel Start -->
  <td width="120" align="center" valign="middle" nowrap id = "Navigation">
   <div class = "style2">
     <a href = "default.php">Home</a><br>
     <a href = "FAQ.php">FAQ</a><br>
     <a href = "Contact.php">Contact Us</a><br>
     <a href = "About.php">About us</a><br>
     <a href = "Cart.php">My Cart</a><br>
   </div>
  </td>
          <!-- Navigation Panel End -->
 
          <!-- Bumper -->
  <td>&nbsp;</td>
          <!-- Bumper -->
 </tr>
</table>
<table width="100%"> 
 <tr>
          <!-- Left Panel Start -->
  <td width="200" colspan="4" align="center" valign="top" nowrap id = "Left_Panel">
   <div class = "style1">
    <div align="center">Categories</div>
    <div align="center"></div> 
   </div>  </td>
          <!-- Left Panel End -->
          <!-- Center Panel Start -->
  <td colspan="5" align="center" valign="top" id = "Center_Panel">
   <div class="style1">
    <div align="center">Templates</div>
    <div align="center">   </div>  </td>
          <!-- Center Panel End -->
 
          <!-- Right Panel Start -->
  <td width="400" align="center" valign="top" nowrap id = "Right_Panel">
   <div class="style1">Preview Image </div>  </td>
          <!-- Right Panel End -->
 </tr>
 <tr>
   <td align="center" valign="top" nowrap class="style8" id = "Left_Panel">&nbsp;</td>
  <td align="center" valign="top" class="style8" id = "Center_Panel"><div align="right">
   <div align="left">Title</div>
   </div></td>
  <td align="center" valign="top" class="style8" id = "Center_Panel"><div align="right">Status</div></td>
  <td align="center" valign="top" class="style8" id = "Center_Panel">&nbsp;</td>
  <td align="center" valign="top" nowrap class="style8" id = "Right_Panel">File Name </td>
  <td align="center" valign="top" nowrap class="style8" id = "Right_Panel">Text Fields </td>
  <td align="center" valign="top" nowrap class="style8" id = "Right_Panel">Categories</td>
  <td align="center" valign="top" nowrap class="style8" id = "Right_Panel">Photos</td>
  <td align="center" valign="top" nowrap class="style8" id = "Right_Panel">Enable</td>
 </tr>
 <tr>
  <td align="center" valign="top" nowrap id = "Left_Panel">&nbsp;</td>
  <td colspan="2" align="center" valign="top" nowrap id = "Left_Panel"><table id= "Categories" name= "Categories" width="100%" align = "center" border="0">
   <?php
$SQL = "Select * From Categories";
$result = mysql_query($SQL);
while($row = mysql_fetch_array($result))
{
 echo (" 
   <tr> 
    <td><div class = 'style8' align = 'left'>".$row['Title']."</div></td>
    <td><div class = 'style8' align = 'right'>".$row['Enable']."</div></td>
   </tr>
   ");
}
?>
  </table></td>
  <td align="center" valign="top" nowrap id = "Left_Panel">&nbsp;</td>
  <td colspan="5" align="center" valign="top" id = "Center_Panel">
<table id= 'Templates' width='100%' align = 'center' border='0'><?php
$SQL = "Select * From Templates";
$result = mysql_query($SQL);
while($row = mysql_fetch_array($result))
{
 echo (" 
   <tr> 
    <td><div class = 'style8' align = 'left'>".$row['FileName']."</div></td>
    <td><div class = 'style8' align = 'right'>".$row['TxtFldCnt']."</div></td>
    <td><div class = 'style8' align = 'left'>".$row['PhotoCnt']."</div></td>
    <td><div class = 'style8' align = 'left'>".$row['Categories']."</div></td>
    <td><div class = 'style8' align = 'right'>".$row['Enable']."</div></td>
   </tr>
   ");
}
?>
</table></td>
  <td align="center" valign="top" nowrap id = "Right_Panel">&nbsp;</td>
 </tr>
 <tr>
  <td align="center" valign="top" nowrap class="style3" id = "Left_Panel">&nbsp;</td>
  <td colspan="2" align="center" valign="top" nowrap class="style3" id = "Left_Panel"><a href = "#" id = "NewCat" name = "NewCat" onClick = "NewCat('Categories')">New Category</a></td>
  <td align="center" valign="top" nowrap class="style3" id = "Left_Panel">&nbsp;</td>
  <td colspan="5" align="center" valign="top" id = "Center_Panel">&nbsp;</td>
  <td align="center" valign="top" nowrap id = "Right_Panel">&nbsp;</td>
 </tr>
</table>
</body>
</html>
URL if you want to take a look, no critique please, under construction. http://trollnest.com/bragflags/Admin...on/default.php

Last edited by Sleeping Troll; 09-02-2008 at 07:05 AM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 09-02-2008, 10:32 AM Re: server script not returning response text AJAX
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Hello, Hello, Hello... Is there anybody there? there? there?
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to server script not returning response text AJAX
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27049 seconds with 12 queries