Ajax related problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yogendra_kaushik
Forum Newbie
Posts: 2
Joined: Tue Jun 24, 2008 4:04 am

Ajax related problem

Post by yogendra_kaushik »

Hello all's
I am new in ajax and XML.When any form data is saved using ajax ( without page refresh ) Then the function return xml ...
How can i do this can any one help me my code is written below.

Code: Select all

 
<?
some required files.
?>
<html>
     <head>
     <title></title>
     <link href="templates/<?php echo $TEMPLATE ?>/css/stylesheet.css" rel="stylesheet" type="text/css" />
     <script type="text/javascript" src="templates/<?php echo $TEMPLATE ?>/javascript/jstb_validations.js"></script>
     <script type="text/javascript" src="templates/<?php echo $TEMPLATE ?>/javascript/AjaxRequest.js"></script>
     <script language="javascript" type="text/javascript">
     function ajaxFunction(sText)
     {
     var ajaxRequest;   // The variable that makes Ajax possible!
     try
     {
          // Opera 8.0+, Firefox, Safari
          ajaxRequest = new XMLHttpRequest();
     }
     catch (e)
     {
          // Internet Explorer Browsers
          try
          {
               ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
               try
               {
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
               }
               catch (e){
                    // Something went wrong
                    alert("Your browser browser is not compitable for the page on which you are working!");
                    return false;
               }
          }
     }
          var device_type_name = document.getElementById('device_type_name').value;
          var reporting_interval = document.getElementById('reporting_interval').value;
          var module = document.getElementById('module').value;
          var version = document.getElementById('version').value;
          var s_key = document.getElementById('s_key').value;
          var uid = document.getElementById('uid').value;
          var lang = document.getElementById('lang').value;
          // This query string is for direct call using class
          //var strUrl = '?device_type_name='+device_type_name+'&reporting_interval='+reporting_interval;
          // This query string is for API call
          var strUrl = '?device_type_name='+device_type_name+'&reporting_interval='+reporting_interval+'&module='+module+'&version='+version+'&s_key='+s_key+'&uid='+uid+'&lang='+lang;
          ajaxRequest.open("GET", "api/index.php" + strUrl,onResponse,true);
          ajaxRequest.send(null);
//             AjaxRequest.get(
//               {
//                  'url':'strUrl','onSuccess':function(){ alert('Success!');
//               }}
//             );
 
//               var ajax = new Ajax();
//               ajax.makeRequest('GET', 'api/index.php', onResponse);
 
 
 
          //blank all field for new entry
          document.getElementById('device_type_name').value='';
          document.getElementById('reporting_interval').value='';
/////////
 
function onResponse()
{
   if(ajax.checkReadyState() == "success")
   {
      // add your parsing code here
     alert("success");
   }
}
}
</script>
     <script type="text/javascript">
          function ChkFrm_data()
          {
            frm=document.add_new_dev_type;
          if(frm.device_type_name.value=="")
               {
                    CustomAlert('<?php echo NECESSARY_FIELD_REQUIRED?>');
                    frm.txt_device_type_name.focus();
                    return false;
               }
          if(frm.reporting_interval.value=="")
               {
                    CustomAlert('<?php echo NECESSARY_FIELD_REQUIRED?>');
                    frm.txt_reporting_interval.focus();
                    return false;
               }
          }
          function CheckInteger(input_object)
          {
               if(!isNumeric(input_object.value))
               {
                    CustomAlert('<?php echo NUMERIC_FIELD_REQUIRED?>');
                    input_object.value = "";
                    //next two   lines are there for compatibility with FireFox
                    myField = input_object;
                    setTimeout("this.myField.focus();",0);
                    //input_object.focus();
                    return false;
               }
          }
          function CustomAlert(message, message_header, message_type)
          {
               alert(message);
          }
     </script>
     </head>
     <body class="body_inner">
          <form action="add_new_dev_type.php" name="add_new_dev_type" method="POST" onSubmit="return ChkFrm_data();">
               <table id="form_container">
                    <tr id="form_header">
                         <td colspan="2"><?php echo HEADING?></td>
                    </tr>
                    <tr id="form_message">
                         <?if(!empty($message)){?>
                         <td colspan="2"><?php echo $message;?></td>                        
                         <?}?>
                    </tr>
                    <tr id="field_row">
                         <td><?php echo DEVICE_TYPE_NAME?></td>
                         <td><input type='text' name='device_type_name' id='device_type_name' value='<?php echo $device_type_name ?>' /></td>
                    </tr>
                    <tr id="field_row">
                         <td><?php echo REPORTING_INTERVAL?></td>
                         <td><input type='text' id="reporting_interval" name='reporting_interval' value='<?php echo $reporting_interval ?>' onChange="return CheckInteger(document.getElementById('txt_reporting_interval'))" /></td>
                    </tr>
                    <tr>
                         <td colspan="2">
                              <input type="hidden" name="module" id="module" value="ADD_DEVICE_TYPE">
                              <input type="hidden" name="version" id="version" value="0.3">
                              <input type="hidden" name="s_key" id="s_key" value="<?php echo $CURRENT_HASH?>">
                              <input type="hidden" name="uid" id="uid" value="<?php echo $USER_ID?>">
                              <input type="hidden" name="lang" id="lang" value="english">
                              <input type="button" onClick="ajaxFunction(add_new_dev_type)" name='Save' value='Save' />
                         </td>
                    </tr>
               </table>
          </form>
     </body>
</html>
 
Post Reply