Jump to content

How to do Ajax in php pages


maideen

Recommended Posts

Hi 

I am not familiar with ajax. pls help me how i can do in script

Below my script  and using pdo and mssql 2005. Below script working fine. But everytime change the details, page refresh and display is delayed

 

Pls help me

 

---------------------------------------------------------------------------

index.php

----------------------------------------------------------------------------------------------

 

 

<?php
include_once '../inc/connection.inc.php';
?>
 
<?php
try {
       $stmt = $dbh->prepare('SELECT * FROM MVendorMaster order by MVName');
       $stmt->execute();
    } 
catch (PDOException $e) 
    {
       $output = 'Error fetching main vendor from database!';
       include '../errormsg.php';
       exit();
    }
 
foreach ($stmt as $row) 
    {
       $mvcode[] = array('MVCode' => $row['MVCode'], 'MVName' => $row['MVName']);
    }
include 'searchform.html.php';
?>
 
<?php
if (isset($_POST['mvendor']) && $_POST['mvendor']  != "" )
    {
        $mvcode = $_POST["mvendor"];
        $datefrom=$_POST["datefrom"];
        $dateto=$_POST["dateto"];
        
        $stmt = $dbh->query("SELECT * FROM InvoiceHead WHERE MVCode='$mvcode' and SODate>='$datefrom' and SODate<='$dateto' order by SODate");  
        $stmt->setFetchMode(PDO::FETCH_ASSOC);  
     }
    include 'view.html.php';
    exit();
   
?>
 
---------------------------------------------------------
searchform.html.php

-------------------------------------------

 

 

<?php
include '../templete/header.php';
?>
 
<form action="" method="post">
        <table>
              <tr>
                  <td>Main Vendor Name </td>
                  <td>
                      <select name="mvendor" id="mvcode"><option value="">Mian Vendor</option>
                    <?php foreach ($mvcode as $mvcodes): ?>
                        <option value="<?php htmlout($mvcodes['MVCode']); ?>">
                            <?php htmlout($mvcodes['MVName']); ?></option>
                    <?php endforeach; ?>
                    </select>
                        
                  </td>
                  
              </tr>
              <tr>
                <td>Date[From]:</td>
                <td><input type="text" id="datepicker1" name="datefrom" /></td>
              </tr>
              <tr>
                <td>Date[To]:</td>
                <td><input type="text" id="datepicker2" name="dateto" /></td>
              </tr>    
 
 
        </table>
  
        <div>
            
            <input type="submit" value="Search">
        </div>
</form>
 

------------------------------------------------------------------------

view.html.php

 

-----------------------------------------------------------------------

 

 

<?php //include '../templete/header.php'; ?>
<script language="javascript" type="text/javascript">
     //window.print();
</script>
 
<script type="text/javascript">
 
        function PrintGridData() {
            var prtGrid = document.getElementById('<%=txtDocNo%>');
            prtGrid.border = 0;
            var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
            prtwin.document.write(prtGrid.outerHTML);
            prtwin.document.close();
            prtwin.focus();
            prtwin.print();
            prtwin.close();
 </script>
 
<table width="100%" align="center" cellpadding="4" cellspacing="1" class=tbl_table">
  <tr>
    <td class="tbl_header">MV CODE</td>
    <td class="tbl_header">MV NAME</td>
    <td class="tbl_header">SONO</td>
    <td class="tbl_header">SO Date</td>
    <td class="tbl_header">RATE</td>
    <td class="tbl_header">SUPP.QTY</td>
    <td class="tbl_header">RTN.QTY</td>
    <td class="tbl_header">BAL.Qty</td>
    <td class="tbl_header">SOLD AMT</td>
    
    
    
    <td class="tbl_header">Actions</td>
    
 
  </tr>
        <?php 
   
        
 
        if(isset($stmt))
            { 
                while($row = $stmt->fetch())
            {?>
    <tr>
      <td class="tbl_content"><?php echo $row['MVCode'];?></td>
      <td class="tbl_content"><?php echo $row['MVName'];?></td>
      <td class="tbl_content"><?php echo $row['SONo'];?></td>
      <td class="tbl_content"><?php echo date("d-m-Y", strtotime($row['SODate']));?></td>
      <td class="tbl_content_right"><?php echo number_format($row['Rate'],2) ;?></td>
      <td class="tbl_content_right"><?php echo number_format($row['Qty']) ;?></td>
      <td class="tbl_content_right"><?php echo number_format($row['RTNQty']) ;?></td>
      <td class="tbl_content_right"><?php echo number_format($row['BalQty']) ;?></td>
      <td class="tbl_content_right"><?php echo number_format($row['BalAmt'],2) ;?></td>
      <!--number_format
      <td>
          <a href="view?=<?php echo $row['SVCode'];?>">View</a> |
          <a href="edit?=<?php echo $row['SVCode'];?>">Edit</a> |
          <a href="delete?=<?php echo $row['SVCode'];?>">Delete</a>
      </td>
    -->
    </tr>
    <?php }}?> 
</table>
 
<?php unset($dbh); unset($stmt); ?>
 
<?php
include '../templete/footer.php';
?>
 

---------------------------------------------

Data connection

---------------------------------------------

 

<?php
  try {
        $hostname = "server";            //host
        $dbname = "db1";            //db name
        $username = "sa";            // username like 'sa'
        $pw = "7hjer34s$%";                // password for the user
        $dbh = new PDO ("mssql:host=$hostname;dbname=$dbname","$username","$pw");
    } 
 
  catch (PDOException $e) 
    {
        echo "cannot connect " . $e->getMessage() . "\n";
        file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
        exit;
    }
?>

 

Pls help how can i add ajax in this page

 

thanking you

 

maideen

Edited by maideen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.