• 2 رای - 3.5 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
كمك فوري در استفاده از ajax
#1
سلام

توي برنامه مي خوام زماني كه كاربر از منوي كشويي 1 گزينه رو انتخاب كرد بر حسب گزينه انتخاب شده اطلاعات از بانك خونده بشه و توي منوي كشويي ديگه اي نمايش داده بشه .
زماني كه كاربر از منوي اول 1 گزينه رو انتخاب ميكنهتوي منوي دومي هيجي نمايش داده نميشه
لطفا كد رو اصلاح كنيد

كد صفحه html‌ :
کد:
<?php
@ ob_start();
@ session_start();
$ClientString = $_SERVER['HTTP_USER_AGENT'];
$_SERVER['REMOTE_ADDR'];
if(!isset($_SESSION['user']) || $_SESSION['ClientStr'] != md5($ClientString))
{
header("location:../index.php");
}
require_once('../lib/db.php');
$link = db_connect();
$q="SELECT `name`,`num` FROM `ghafaseh` ORDER BY `num`";
$result = db_query($q);
?>
<html>
<head>
<meta http-equiv="Content-Language" content="fa">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="ajax.js"></script>
<title>فرم برداشت جنس از انبار</title>
<link rel="stylesheet" type="text/css" href="../lib/Style.css">
<script language="javascript">
function jensmsg() {
if (document.jens.gh.value == ""){
alert('لطفا نام / شماره قفسه را انتخاب  کنید');
return false;
}if (document.jens.name.value == ""){
alert('لطفا نام جنس را انتخاب  کنید');
return false;
}if (document.jens.count.value == ""){
alert('لطفا تعداد را وارد کنید');
return false;
}if (document.jens.count.value.match(/[&<>A-Za-zآ-ی (-('(")_.,;:*?]+/)){
alert('لطفا برای تعداد از کاراکترهای غیر مجاز استفاده نکنید');
return false;
}if (document.jens.pricekh.value == ""){
alert('لطفا قیمت فروش را وارد کنید');
return false;
}if (document.jens.pricekh.value.match(/[&<>A-Za-zآ-ی (-('(")_.;:*$]+/)){
alert('لطفا برای قیمت فروش از کاراکترهای غیر مجاز استفاده نکنید');
return false;
}
}
</script>
<script>
function num2money(num){
    num=money2num(num);
    
    var le=num.length;
    var money='';
    var c=0;
    for(a=le-1;a>=0;a--){
        c++;
        if(c%3==1 && c>1) theChar=','; else theChar='';
        money=num.substr(a,1)+theChar+money;
    }
    
    return money;
}

function money2num(money){
    var num=money.replace(/,/g,'');
    
    return num;
}
</script>
</head>

<body topmargin="0" background="../image/bg.gif">

<div align="right">
    <table border="0" width="50%" cellpadding="2">
        <form method="POST" name="jens">
        <tr>
            <td height="15">
            <div align="right">
                <table border="0" width="70%">
                    <tr>
                        <td>
                        <p align="right"><b>
                        <font face="Tahoma" style="font-size: 9pt" color="#333333">&nbsp;فرم
                        برداشت جنس</font></b></td>
                        <td width="32">
                        <p align="right">
                        <img border="0" src="../image/archive.gif" width="32" height="32"></td>
                    </tr>
                </table>
            </div>
            </td>
        </tr>
        <tr>
            <td>
            <div align="center">
                <table border="0" width="100%" dir="rtl">
                    <tr>
                        <td align="right" bgcolor="#F3F3F3">
                        <font face="Tahoma" style="font-size: 9pt" color="#333333">
                        نام / شماره قفسه </font>
                        <font face="Tahoma" style="font-size: 9pt" color="#CC0000">
                        <span lang="en-us">*</span></font><font face="Tahoma" style="font-size: 9pt" color="#333333">
                        <span lang="en-us">:</span></font></td>
                        <td align="right" width="331">
                        <p dir="rtl">
                        <select size="1" name="gh" dir="rtl" id="gh" class="in" onchange="javascript:Getjens()">
                        <option selected value="">----------------</option>
                        <?php
                    while ($line2 = db_fetch_assoc($result))
                     {
                     ?>
                    <option value="<?php  echo($line2['num']);?>">
                    <?php  echo($line2['num'].' ('.$line2['name'].' )');?>
                    </option>

<?php
}
?>
                        </select></td>
                    </tr>
                    <tr>
                        <td align="right" bgcolor="#F3F3F3">
                        <font face="Tahoma" style="font-size: 9pt" color="#333333">
                        نام جنس<span lang="en-us"> </span></font>
                        <font face="Tahoma" style="font-size: 9pt" color="#CC0000">
                        <span lang="en-us">*</span> </font>
                        <font face="Tahoma" style="font-size: 9pt" color="#333333">
                        <span lang="en-us"> :</span></font></td>
                        <td align="right" width="331">
                        <select size="1" name="name" dir="rtl" class="in" id="name">
                    <option selected value="">----------------</option>
                    </select></td>
                    </tr>
                    <tr>
                        <td align="right" bgcolor="#F3F3F3">
                        <font face="Tahoma" style="font-size: 9pt" color="#333333">
                        تعداد </font>
                        <font face="Tahoma" style="font-size: 9pt" color="#CC0000">
                        <span lang="en-us">*</span> </font>
                        <font face="Tahoma" style="font-size: 9pt" color="#333333">
                        :</font></td>
                        <td align="right" width="331">
                        <input type="text" name="count" size="20" dir="ltr" class="in" maxlength="11"></td>
                    </tr>
                    <tr>
                        <td align="right" bgcolor="#F3F3F3">
                        <font face="Tahoma" style="font-size: 9pt" color="#333333">
                        قیمت فروش </font>
                        <font face="Tahoma" style="font-size: 9pt" color="#CC0000">
                        <span lang="en-us">*</span> </font>
                        <font face="Tahoma" style="font-size: 9pt" color="#333333">
                        :</font></td>
                        <td align="right" width="331">
                        <input type="text" name="price" size="20" dir="ltr" onkeyup="this.value=num2money(this.value);" class="in"></td>
                    </tr>
                    </table>
            </div>
            </td>
        </tr>
        <tr>
            <td height="49">
            <p align="center" dir="rtl">
            <span lang="en-us">&nbsp;
            </span><input type="reset" value="فرم جدید" class="button"><span lang="en-us">&nbsp;
            </span>
            <input type="submit" value="برداشت جنس" class="button" onclick="return jensmsg();"></td>
        </tr>
        </form>
    </table>
</div>

</body>

</html>


كد برنامه پي اچ پي :

کد پی‌اچ‌پی:
<head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</
head>
<?
php
ob_start();
session_start();
$ClientString $_SERVER['HTTP_USER_AGENT'];
$_SERVER['REMOTE_ADDR'];
if(!isset(
$_SESSION['user']) || $_SESSION['ClientStr'] != md5($ClientString))
{
header("location:../index.php");
}
require_once(
'../lib/db.php');
$gh=$_POST['gh'];
$link db_connect();
$q "SELECT `name`,`model` FROM `jens` WHERE `ghafaseh`='$
كد آي جكس كgh'"
;
$result db_query($q);
$r=mysql_num_rows($result);
if (
$r<='0')
{
echo 
"<script>alert('در قفسه شماره $gh هیچ جنسی ثبت نشده است')</script>";
echo 
"<meta http-equiv='refresh'  content='0; URL=Formbardashtjens.php'>"; exit();
}
else 
{
$q="SELECT * FROM `jens` WHERE `ghafaseh`='$gh'";
$reg db_query($q);
$line db_fetch_assoc($reg)
echo (
$line['name'].' ('.$line['model'].' )');
}
db_close($link);
?>
كد آي جكس :

کد:
function createXMLHttp(){
    if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            var aVersions = [ "MSXML2.XMLHttp.5.0",
                    "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0",
                        "MSXML2.XMLHttp", "Microsoft.XMLHttp" ];
for (var i = 0; i < aVersions.length; i++) {
    try {
    var oXmlHttp = new ActiveXObject(aVersions[i]);
    return oXmlHttp;
    } catch (e) {} }
    } throw new Error("XMLHttp object could not be created."); }

    function Getjens()
{
var oXmlHttp= createXMLHttp();
  var type;
  gh=document.getElementById('gh').value;
if (gh==0){
    showdata('');
    return;
}
  gh = 'gh='+ escape(encodeURI(gh))+"&";
  oXmlHttp.open("POST","getjens.php",true);
  oXmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
  oXmlHttp.setRequestHeader("Content-length", type.length);
  oXmlHttp.setRequestHeader("Connection", "close");
  oXmlHttp.onreadystatechange = function() {
        if (oXmlHttp.readyState == 4) {
            if(oXmlHttp.status == 200){
                showdata(oXmlHttp.responseText);
            } else {
                showdata("Error: " + oXmlHttp.statusText);
            }
        }
    };
    oXmlHttp.send(type);
}
function showdata(Cdata){
    document.getElementById('name').value = Cdata ;
}
  پاسخ
تشکر شده توسط :
#2
این نمونه کد رو نگاه کن و بعد خودت ببین کجا مشکل داری.
غایب
  پاسخ
تشکر شده توسط :


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان