By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

problem in using ajax function

P: 19
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using:
[PHP]
<?
include("config.inc.php");
//error_reporting(0);


if(isset($_REQUEST['Submitstore2'])=="Delete")
{
$storeno=$_REQUEST['storeno'];
$sql_storedelete="delete from store_info where storeid='$storeno'";
mysql_query($sql_storedelete);

}
if(isset($_REQUEST['Submitstore'])=="Update")
{

$storeno=$_REQUEST['storeno'];
$storename=$_REQUEST['storename'];
$warehousename=$_REQUEST['warehousename'];
$storecontactno=$_REQUEST['contactno'];
$note=$_REQUEST['note'];
$storecontactperson=$_REQUEST['contactperson'];

if($storeno!="" && $storename!="" && $warehousename!="" && $storecontactno!="" && $note!="" && $storecontactperson!="")
{
$sql_storeupdate="UPDATE `store_info` SET `storename`='$storename', `warehouse`='$warehousename', `contactperson`='$storecontactperson', `contactno`='$storecontactno',`note`='$note' WHERE `storeid`='$storeno'";
//echo $sql_storeupdate;
mysql_query($sql_storeupdate);
$msg="updated";
}
else
{
$msg="error";
}
}

?>[/PHP][HTML]
<html>
<head><title>store Details</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="<?php echo $NF_config['css_file'];?>" rel="stylesheet" type="text/css">
<link href="_css/nf_style.css" rel="stylesheet" type="text/css">
<style type="text/css">
.style1 {font-size: 9}
</style>
<link href="../../_css/nf_style.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript">[/HTML]
Expand|Select|Wrap|Line Numbers
  1.   function loadIndividual(form) {
  2.     var gifName=form.storeimageupload.value;
  3.     document.getElementById('hidimg').value=gifName;
  4.     //alert(gifName);
  5.     document.getElementById('storeimage').src=gifName;
  6.  
  7. }
  8. function backtomain()
  9. {
  10. window.location="http://localhost/sugarcub_erp/sugarcub_inventory/in.php";
  11.  
  12.  
  13. }
  14. //problem in this ajax functions
  15. function ajaxfunctionstore(text){
  16.  
  17.  
  18.     var ajaxRequest;  // The variable that makes Ajax possible!
  19.  
  20.     try{
  21.         // Opera 8.0+, Firefox, Safari
  22.         ajaxRequest = new XMLHttpRequest();
  23.     } catch (e){
  24.         // Internet Explorer Browsers
  25.         try{
  26.             ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  27.         } catch (e) {
  28.             try{
  29.                 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  30.             } catch (e){
  31.                 // Something went wrong
  32.                 alert("Your browser broke!");
  33.                 return false;
  34.             }
  35.         }
  36.     }
  37.     // Create a function that will receive data sent from the server
  38.     ajaxRequest.onreadystatechange = function(){
  39.         if(ajaxRequest.readyState == 4){
  40.              var  x=ajaxRequest.responseText;
  41.             //alert(x);
  42.              var gettype=x.split("*");
  43.              var  getlen=gettype.length;
  44.              getlen=getlen-1;
  45.              document.forms['store_update_form_entry'].storeno.value = gettype[0];
  46.              document.forms['store_update_form_entry'].storename.value = gettype[1];
  47.              document.forms['store_update_form_entry'].warehousename.value = gettype[2];
  48.              document.forms['store_update_form_entry'].contactperson.value = gettype[3];
  49.              document.forms['store_update_form_entry'].contactno.value = gettype[4];            
  50.              document.forms['store_update_form_entry'].note.value = gettype[5];
  51.  
  52.         }
  53.     }
  54.     var username=text;
  55.     //var wpm = document.getElementById('wpm').value;
  56.     //var sex = document.getElementById('sex').value;
  57.     var queryString = "?username=" + username;
  58.     //alert(queryString); 
  59.     ajaxRequest.open("POST","http://localhost/sugarcub_erp/sugarcub_inventory/storeupdateno.php" + queryString, true);
  60.       ajaxRequest.send(null); 
  61.  
  62. }
  63. function ajaxfunctionstorename(text){
  64.  
  65.  
  66.     var ajaxRequest;  // The variable that makes Ajax possible!
  67.  
  68.     try{
  69.         // Opera 8.0+, Firefox, Safari
  70.         ajaxRequest = new XMLHttpRequest();
  71.     } catch (e){
  72.         // Internet Explorer Browsers
  73.         try{
  74.             ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  75.         } catch (e) {
  76.             try{
  77.                 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  78.             } catch (e){
  79.                 // Something went wrong
  80.                 alert("Your browser broke!");
  81.                 return false;
  82.             }
  83.         }
  84.     }
  85.     // Create a function that will receive data sent from the server
  86.     ajaxRequest.onreadystatechange = function(){
  87.         if(ajaxRequest.readyState == 4){
  88.              var  x=ajaxRequest.responseText;
  89.             //alert(x);
  90.              var gettype=x.split("*");
  91.              var  getlen=gettype.length;
  92.              getlen=getlen-1;
  93.  
  94.             document.forms['store_update_form_entry'].storeno.value = gettype[0];
  95.              document.forms['store_update_form_entry'].storename.value = gettype[1];
  96.              document.forms['store_update_form_entry'].warehousename.value = gettype[2];
  97.              document.forms['store_update_form_entry'].contactperson.value = gettype[3];
  98.              document.forms['store_update_form_entry'].contactno.value = gettype[4];            
  99.              document.forms['store_update_form_entry'].note.value = gettype[5];
  100.  
  101.  
  102.         }
  103.     }
  104.     var username=text;
  105.     //var wpm = document.getElementById('wpm').value;
  106.     //var sex = document.getElementById('sex').value;
  107.     var queryString = "?username=" + username;
  108.     //alert(queryString); 
  109.     ajaxRequest.open("POST","http://localhost/sugarcub_erp/sugarcub_inventory/storeupdatename.php" + queryString, true);
  110.       ajaxRequest.send(null); 
  111.  
  112. }//problem in this ajax functions//
  113.  
  114.  
  115. function setstoregrade(text)
  116. {
  117. document.getElementById('storegrade').value=text;
  118. }
  119. function showstoreno()
  120. {
  121. document.getElementById('storenoimage').style.display='inline';
  122. document.getElementById('storeselect_div').style.display='inline';
  123. document.getElementById('storeno_div').style.display='inline';
  124. document.getElementById('storenameimage').style.display='none';
  125. document.getElementById('storename_div').style.display='none';
  126. document.getElementById('storenameselect_div').style.display='none';
  127. }
  128. function showstorename()
  129. {
  130.  
  131. document.getElementById('storenoimage').style.display='none';
  132. document.getElementById('storeselect_div').style.display='none';
  133. document.getElementById('storeno_div').style.display='none';
  134. document.getElementById('storenameimage').style.display='inline';
  135. document.getElementById('storename_div').style.display='inline';
  136. document.getElementById('storenameselect_div').style.display='inline';
  137. }
  138. function setwarehousename(text)
  139. {
  140. document.getElementById('warehousename').value=text;
  141. }
[HTML]
</script>
</head>

<body alink="#FFFFFF" vlink="#FFFFFF" link="#FFFFFF" >
<form name="store_update_form_entry" id="store_update_form_entry" action="" method="post" onSubmit="return check(document.department_form_entry)" >
<input type="hidden" name="hidimg" id="hidimg" >
<table width="528" height="370" border="0" align="center" cellpadding="0" cellspacing="0">

<? if($msg=="updated"){?>
<tr>
<td align="center" colspan="2"><font color="#FF0000">store Detail is Updated </font></td>
</tr><? } ?>
<? if($msg=="error"){?>
<tr><td align="center" colspan="2"><font color="#FF0000"><img src="_images/errormessage.gif">Some field not not Filled</font></td></tr><? } ?>
<tr><td>
<table align="right" bgcolor="#A8D3FF" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" style="font-size:18px; font-weight:bold">EDIT LOCATION </td>
</tr>
</table></td></tr>
<tr><td align="left" colspan="2"><div id="searchstorediv"><fieldset style="border-color:#006699">
<legend class="sugarcube_logo11">Store Search</legend>
<table width="524">
<tr>
<td class="sugarcube_logo11">&nbsp;Search store BY: </td>
//here i call the ajax functions


<td style="font-size:13px; font-weight:bold;cursor:pointer"><font color="#003366"><b onClick="showstorename();">Store Name</b></font><img name="storenameimage" id="storenameimage" src="_images/gif/tick.gif" style="display:none"><b style="font-size:18px">/</b><font color="#003366"><b onClick="showstoreno();">Store No.</b></font><img name="storenoimage" id="storenoimage" src="_images/gif/tick.gif" style="display:none"></td>
</tr>
<tr>
<td width="218" class="sugarcube_logo11"><div id="storename_div" style="display:inline">&nbsp;Store Name</div>
<div id="storeno_div" style="display:none">Store No.</div>.</td>
<td width="294"><div id="storeselect_div" style="display:none"><select name="storenosearch" id="storenosearch" onChange="ajaxfunctionstore(this.value)"><option value="">Select store NO.</option><? echo getstoreno(); ?></select></div>
<div id="storenameselect_div" style="display:inline">
<select name="storesearchname" id="storesearchname" onChange="ajaxfunctionstorename(this.value)">
<option value="">Select store Name</option>
<? echo getstorename(); ?>
</select>
</div></td></tr></table>
</fieldset></div></td></tr>
<tr><td width="528" height="335" valign="top"><fieldset style="border-color:#006699">

<legend class="salary_text21">Store Details</legend>
<table width="524" border="0" cellspacing="0" cellpadding="0">

<tr>
<td width="524" height="186" colspan="2" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="5" colspan="3"></td>
</tr>
<tr>
<td height="20" class="sugarcube_logo11">&nbsp;Store No.:</td>
<td width="135"><input name="storeno" id="storeno" type="text" class="style1"></td>
<td width="162">&nbsp;</td>
</tr>
<tr>
<td height="20" class="sugarcube_logo11">&nbsp;Store Name:</td>
<td><input name="storename" id="storename" type="text" class="style1"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="227" height="20" class="sugarcube_logo11">&nbsp;Warehouse Name :</td>
<td><input name="warehousename" id="warehousename" type="text" class="style1" readonly></td>
<td><select name="warehouseselect" id="warehouseselect" style="width:120px" onChange="setwarehousename(this.value);">
<option value="select">Select Warehouse</option>
<?=getwarehousename();?>
</select></td>
</tr>

<tr>
<td width="227" height="20" class="sugarcube_logo11">&nbsp;Contact Person: </td>
<td><input name="contactperson" id="contactperson" type="text" class="style1"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="227" height="20" class="sugarcube_logo11">&nbsp;Contact No :</td>
<td><input name="contactno" id="contactno" type="text" class="style1"></td>
<td>&nbsp;</td>
</tr>


<tr>
<td height="69" class="sugarcube_logo11">&nbsp;Note:</td>
<td colspan="2"><textarea name="note" id="note" cols="40" rows="4"></textarea></td>
</tr>

<tr bordercolor="#006699">
<td colspan="3" align="RIGHT"><input type="submit" name="Submitstore" id="Submitstore" value="Update"> <input type="submit" name="Submitstore2" id="Submitstore2" value="Delete"> <input type="button" name="back" id="back" value="Back To Main Page" onClick="backtomain();"></td>
</tr>


</table></td>
</tr>
</table>
</fieldset>
</td>
</table>

</form>
<div align="center">[/HTML]
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function check(frm)
  3. {
  4. var out="";
  5.     if(frm.department_name.value==""){
  6.     document.getElementById('department_name_text_error').innerHTML='&bull;Please Fill Department Name';
  7.     out=1
  8.     }
  9. if(frm.department_id.value==""){
  10.     document.getElementById('department_id_text_error').innerHTML='&bull;Please Fill Department Id';
  11. out=1
  12.     }
  13.     if(frm.department_role.value==""){
  14.     document.getElementById('department_role_text_error').innerHTML='&bull;Please Fill Department Role';
  15. out=1
  16.     }
  17.     if(frm.department_date.value==""){
  18.     document.getElementById('department_date_text_error').innerHTML='&bull;Please Fill Department Date';
  19. out=1
  20.     }
  21.     if(frm.department_by.value==""){
  22.     document.getElementById('department_by_text_error').innerHTML='&bull;Please Fill Department By';
  23. out=1
  24.     }
  25.  
  26. if(out=="")
  27.         return true;
  28.     else
  29.         return false;
  30.  
  31. }
[HTML]
</script>
</div>
</body>
</html>[/HTML][PHP]
<?

function getstoreno()
{

$sql="select * from store_info";
$query=mysql_query($sql);
while($fetch=mysql_fetch_assoc($query))
{

$select="";
$str.="<option value='".trim($fetch['storeid'])."'$select>".$fetch['storeid']."</option>";
}

return $str;

}
function getstorename()
{

$sql="select * from store_info";
$query=mysql_query($sql);
while($fetch=mysql_fetch_assoc($query))
{

$select="";
$str.="<option value='".trim($fetch['storename'])."'$select>".$fetch['storename']."</option>";
}

return $str;

}

function getwarehousename()
{

$sql="select * from warehouse_info";
$query=mysql_query($sql);
while($fetch=mysql_fetch_assoc($query))
{

$select="";
$str.="<option value='".trim($fetch['warehousename'])."'$select>".$fetch['warehousename']."</option>";
}

return $str;

}
?>


and this the the php file used in ajax function:
Storeupdatename:
<?
global $str;

$storename=$_REQUEST['username'];
$link=mysql_connect("localhost","root","");
$db=mysql_select_db("sugarcub_inventory");
$sql="select * from store_info where storename='$storename'";
$rs=mysql_query($sql) or die("ERROR - ".mysql_error());
while($fetch=mysql_fetch_array($rs))
{
$str.=$fetch['storeid']."*".$fetch['storename']."*".$fetch['warehouse']."*".$fetch['contactperson']."*".$fetch['contactno']."*".$fetch['note']."*";
}


echo $str;
?>

Storeupdateno:
<?
global $str;

$storeno=$_REQUEST['username'];
$link=mysql_connect("localhost","root","");
$db=mysql_select_db("sugarcub_inventory");
$sql="select * from store_info where storeid='$storeno'";
$rs=mysql_query($sql) or die("ERROR - ".mysql_error());
while($fetch=mysql_fetch_array($rs))
{
$str.=$fetch['storeid']."*".$fetch['storename']."*".$fetch['warehouse']."*".$fetch['contactperson']."*".$fetch['contactno']."*".$fetch['note']."*";
}


echo $str;
?>[/PHP]
Sep 16 '07 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
shivendravikramsingh, start using CODE tags. Now.

[CODE=php]
PHP code goes here.
[/CODE]
Sep 16 '07 #2

acoder
Expert Mod 15k+
P: 16,027
You're making a POST request and sending the parameters using the URL. Either make it a GET request or send the parameters using the send method.
Sep 16 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.