save me please! AJAX->PHP->XML->AJAX crashing ajax


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: save me please! AJAX->PHP->XML->AJAX crashing ajax

  1. #1
    Join Date
    May 2009
    Posts
    2

    Unhappy save me please! AJAX->PHP->XML->AJAX crashing ajax

    I'm working on a pretty sweet system for updating multiple div tags with data through the use of a php backbone connecting to a mysql server and returning xml containing the div id and the html to be placed in the div. (this requires the html to be encased in cdata brackets which is slightly ghetto, but it works).

    Long story short, ive got this system working... almost. My request goes out and gets all the data from the php server like its supposed to then returns it. the javascript parses it and places it in the page... but then.

    pouf. its all gone. The updates that were made inside the div tags just simply disappear and the original page reloads (so it seems).

    its up and public at
    http://65.171.234.31:8888/ContactManager/
    also, i can put the files up to anyone who wants to help from their local server.

    if your not a member and you see something, email me at tommy.g.heller@gmail.com

    watch the breaks as it loads the data then drops out.

    code below as follows Javascript, php processor, php include file being accessed. the index thats at the main.

    This is a slightly complex system. The javascript pulls the variables that come in its formal paramaters then check the form name for data and adds that into one post. the post travels to processor.php; this script uses the variable names to create variable variables to call the proper classes and functions according to the POST. in this case, its the initial login screen and its posting to the checklogin function under the security class. all this works properly. the information comes back to the browser in proper xml format and is processed by the javascript function flawlessly right up until the moment that it ends.. and like i said, pouf. my changes dissapear.
    Code:
    Javascript function
    function process(theclass, classvars, thefunction, functionvars, form)
    {
        alert('running process()');
        var handler = "processor.php";
        var post = "class="+theclass+"&thefunction="+thefunction;
        if(classvars)
        {
            for(x in classvars)
            {
                post += "&classvars[]="+classvars[x];
            }
        }
        if(functionvars)
        {
            for(x in functionvars)
            {
                post += "&functionvars[]="+functionvars[x];
            }
        }
        alert(post);
        var postadition = '';
        theform = document.getElementById(form);
        for(var i=0; i<theform.elements.length; i++)
        {
            alert("processing form");
                
            var value;
    
            
            if(theform.elements[i].name=="selected")
            {
                if(theform.elements[i].checked){
                    value = theform.elements[i].value;
                    value = escape(value);
                    postadition += '&'+theform.elements[i].name+'='+value;
    
                }
            }
    
            else
            {
                //	alert('this is happening');
                postadition += '&'+theform.elements[i].name;
                postadition += '='+theform.elements[i].value;
            }
    
        }
         var sendpost = post+postadition;
         alert(sendpost);
        var currequest = GetXmlHttpObject();
    
    
        currequest.open("POST", handler, false);
        currequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
        currequest.onreadystatechange = function()
        {
            //alert('ready state changed');
            if(currequest.readyState == 4 && currequest.status == 200)
            {
                text = currequest.responseText;
                 alert(text);
                try //Internet Explorer
                {
                    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async="false";
                    xmlDoc.loadXML(text);
                }
                catch(e)
                {
                    try //Firefox, Mozilla, Opera, etc.
                    {
                        parser=new DOMParser();
                        xmlDoc=parser.parseFromString(text,"text/xml");
                    //                alert(xmlDoc);
                    }
                    catch(e)
                    {
                        alert(e.message);
                        return;
                    }
                }
    
                var root = xmlDoc.getElementsByTagName('changes');
                          alert(root.length);
                var items = xmlDoc.getElementsByTagName('selection');
                            alert(items.length);
                for (var i = 0 ; i < items.length ; i++) {
                    //        alert('working');
                    var contents = items[i];
                    var divId = contents.getElementsByTagName("DIVID")[0].firstChild.nodeValue;
                    alert(divId);
                    var divContents = contents.getElementsByTagName("DIVHTML")[0].firstChild.nodeValue;
                    alert(divContents);
                    var changing = document.getElementById(divId);
                    changing.innerHTML =  divContents;
                    alert("hold1");
                }
                //delete xmlDoc;
                //delete parser;
                alert("hold2");
            }
            else if(currequest.readyState == 4 && currequest.status != 200)
            {
                throw('Server response error. Server error:'+currequest.statusText);
            }
            alert("hold3");
        }
        // alert(post);
       
        //alert(sendpost);
        currequest.send(sendpost);
        //alert("hold4");
    }
    
    
    php processor
    
    <?php
    /* 
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    //error_log($_POST);
    if(set_include_path('.:/Applications/MAMP/htdocs/ContactManager/****itup/'))
    {
    error_log('include path set');
    }
    else
    {
        error_log('include path set failed');
    }
    function __autoload($classname)
    	{
    	require_once($classname.'.inc');
    	}
    $class = $_POST['class'];
    
    $classvars = $_POST['classvars'];
    
    $function = $_POST['thefunction'];
    
    $functionvars = $_POST['functionvars'];
    
    header("Content-Type: text/xml");
    error_log($class.'....'.$function);
    try
         {
            if($classvars == 'null' && $functionvars != 'null')
                {
                    error_log('response 1 used');
                    $object = new $class();
                        echo $object->$function($functionvars);
    
    
                }
            elseif($functionvars == 'null' && $functionvars == 'null')
            {
                error_log('response 2 used');
              $object = new $class();
    
                        echo $object->$function();
            }
            elseif($functionvars != 'null' && $functionvars == 'null')
            {
                error_log('response 3 used');
              $object = new $class($classvars);
    
                        error_log( $object->$function());
                        echo $object->$function();
            }
            else
            {
                error_log('response 4 used');
                $object = new $class($classvars);
                $response = $object->$function($functionvars);
                echo $response;
    
            }
            error_log($response);
         }
     catch(Exception $e)
        {
            error_log($e);
        }
    ?>
    php inc file being called

    at http://65.171.234.31:8888/ContactManager/security.inc

    sorry i couldnt post, post was too long.
    Code:
    index that the action is occuring on
    
    <!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>
    <?
    set_include_path('.:/Applications/MAMP/htdocs/ContactManager/');
    ?>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    #controlHeader {
    	position:absolute;
    	left:17px;
    	top:9px;
    	width:813px;
    	height:26px;
    	z-index:1;
    }
    #list {
    	position:absolute;
    	left:17px;
    	top:46px;
    	width:163px;
    	height:600px;
    	z-index:2;
    }
    #display {
    	position:absolute;
    	left:185px;
    	top:46px;
    	width:644px;
    	height:600px;
    	z-index:3;
    }
    -->
    </style>
    <script src="./processor.js"></script>
    <script type="text/javascript">
       
    
    </script>
    </head>
    
    <body>
    <div id="controlHeader"></div>
    <div id="list"></div>
    <div id="display"><form id="login" name="login">
                          <label></label>
                          <table border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td><label>
                              Please Login To Access Admin Privileges
                                <div align="right">User Name:
                                  <input type="text" name="username" id="username" />
                             Password:
                                  <input name="password" type="password" id="password" />
                                </div>
                                </label>
    
                                </td>
                            </tr>
                          </table>
                        </form> <a href onclick='process("security", "","checkLogin","", "login");' >login</a></div>
    </body>
    </html>
    Last edited by merryfknpoppins; 05-19-2009 at 03:36 PM. Reason: Added Code Tags

Similar Threads

  1. AJAX Help - save only works sometimes
    By dzirkelb in forum AJAX
    Replies: 0
    Last Post: 03-24-2009, 01:01 PM
  2. AJAX, cURL, and PHP
    By chivkea in forum AJAX
    Replies: 0
    Last Post: 03-22-2007, 10:15 PM
  3. Why use XML?
    By Brian in forum XML
    Replies: 5
    Last Post: 01-10-2003, 09:39 PM
  4. Try XML Junction
    By Tim in forum xml.announcements
    Replies: 0
    Last Post: 10-11-2001, 05:00 PM
  5. Data Junction Announces XML Junction 7.51
    By Tim Frost in forum xml.announcements
    Replies: 0
    Last Post: 04-02-2001, 11:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center