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.

JavaScript Forum


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



Reply
AJAX Script does not post.
Old 04-11-2009, 07:26 PM AJAX Script does not post.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
The function "Handler()" generates my post string, in the alert all appears well, however The server does not receive post! the response text which is generated via "var_dump($_POST['Entry']);" is "NULL"...
Anybody got a clue?


Code:
 
function Handler(Button,Msg)
{
var FormData = "";
if (Msg)
{
var DoIt=confirm(Msg)
if (DoIt==true)
{
try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { alert("Error: Could not load page.");}
Column = 0
while (Column <= Columns)
{
switch (document.getElementById(Title[Column]).tagName)
{
case "DIV":
if (document.getElementById(Title[Column]).innerHTML>"")
{
FormData = FormData + Title[Column] + "=" + escape(document.getElementById(Title[Column]).innerHTML) + "&";
}
break;
 
case "INPUT":
if (document.getElementById(Title[Column]).value>"")
{
FormData = FormData + "Entry["+(Column-OffSet)+"]=" + escape(document.getElementById(Title[Column]).value) + "&";
}
break;
 
case "TEXTAREA":
if (document.getElementById(Title[Column]).innerHTML>"")
{
FormData = FormData + "Entry["+(Column-OffSet)+"]=" + escape(document.getElementById(Title[Column]).innerHTML) + "&";
break;
}
}
Column = Column + 1;
}
FormData = FormData + "Button=" + Button + "&Sender=" + document.getElementById("Sender").value;
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4)
{
alert(xmlhttp.responseText);
}
}
alert(FormData)
xmlhttp.open("POST","Handler.php?"+FormData,true);
xmlhttp.send(null);
return false;
}
}
}
Ajax handler code:

PHP Code:
<?php
require_once('../Connections/Hawks.php');
mysql_select_db($database_Hawks$Hawks);
var_dump($_POST['Entry']);
  switch (
$_POST['Button'])
   {
    case 
"Save":
     
$SQL="Show Columns From ".$_POST['Sender'];
     
$ColumnTitles mysql_query($SQL) or die("Could not connect Column Titles: " mysql_error());
     while (
$Title mysql_fetch_assoc($ColumnTitles))
     {
      
$i++;
      
$SQL "Update ".$_POST['Sender']." Set ".$Title[Field]."='".$_POST['Entry'][$i]."' Where ".$_POST['Sender']."ID = '".$_POST['Sender']."ID'";
      echo (
"Hello ".$_POST['Button'].", ".$SQL);
      
//mysql_query($SQL);
     
}
    break;
    case 
"Delete":
     
$SQL "";
     break;
   }
?>
This is the alert value for FormData:

ClientsID=1&Entry[0]=14&Entry[1]=Friday&Entry[2]=Handy%20Foods%20%236161&Entry[3]=9308%20Balm%20Riverview%20Rd.&Entry[4]=Riverview&Entry[5]=FL&Entry[7]=%28813%29%20677-7294&Button=Save&Sender=Clients

Hence the post string "Handler.php?ClientsID=1&Entry[0]=14&Entry[1]=Friday&Entry[2]=Handy%20Foods%20%236161&Entry[3]=9308%20Balm%20Riverview%20Rd.&Entry[4]=Riverview&Entry[5]=FL&Entry[7]=%28813%29%20677-7294&Button=Save&Sender=Clients"

I have substituted "Get" and the address bar reflects this string.

The purpose of all this is that it will populate a preconstructed form and allow navigation and editing of the corresponding database. without changes needed to accomodate either. I should be able to break this up into discrete scripts and use them for the other forms and databases in the site.
__________________
Sleeping Troll, EMUSE, Mind Expansion...Truly serendipity!

Last edited by Sleeping Troll; 04-12-2009 at 08:46 AM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to AJAX Script does not post.
 

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.59692 seconds with 12 queries