0

所以我一直在研究这个系统,当你在 Mysql 上的权限表中获得一个新数字时,它会自动更新一个场景选择页面。我有用于登录的 Php,以及用于在成员表的权限行中获取数字的 Php 工作正常。

我的问题在于 Jquery(我昨天开始使用它:p)我在连接到这个 php 文档的脚本的开头添加了一个 Jquery Ajax 连接:

连接.php:

<?php
mysql_connect($dbhost, $dbuser, $dbpass);
    //Select Database
mysql_select_db($dbname) or die(mysql_error());
    // Retrieve data from Query String


//this selects everything for the current user, ready to be used in the script below

$result = mysql_query("SELECT * FROM members WHERE username = '".$_SESSION['Username']."' LIMIT 1");

//this function will take the above query and create an array


 //with the array created above, I can create variables (left) with the outputted array (right)
 while($row = mysql_fetch_array($result)) { var_dump($row); $permission = $row['permission']; }



        echo '<u><b>Permision ID:</b></u> - - No:' .$permission  ; 
?>

效果很好,我登录后去了那个公园,它完美地回忆了所有数据。我相信问题出在 JQuery 上。

index.php - jQuery:

<script type="text/javascript" src="jquery-1.9.1.min.js"></script> 
<script type="text/javascript">

 $.ajax({
   url:'connect.php',
   datatype:"application/json",
   type:'get',
   data: 'q='+permission, 
   success:function(data){
      count('#result').append(html); 
   },
   error:function(){
      // code for error
   }
 });



        if (['permission'] = '1') {
            $('#middle').load(function() {
      $('#Scene1').fadeIn('slow', function() {
        // Animation complete
      });
    });

    }
    //2,3,4,5,6 ommited

    });

    }

        if (['permission'] = '7') {
            $('#middle').load(function() {
      $('#Scene7').fadeIn('slow', function() {
        // Animation complete
      });
    });

    }

//-->
</script>   

该脚本应该将显示样式设置为继承,以便在数据库中的数字与场景的数字相同时可以看到它。

只是给你一些背景,这是我的场景。

#场景1:

    <div id="middle">





        <ul id="Scene1" style="display:none;">

<h2 id="unlocked">Act One</h2>
            <li id="navi3"><a href="#"><img src="Images/Scene-one-unlocked-unpressed.png" alt="Scene One completed" height="255px" width="340px"/></li></a>
    <img id="arrow"
    src="Images/Right-Arrow.png" 
    height="80px"
    width="120px"/>
            <li id="navilockedr"><img src="Images/Scene-two-locked.png" alt="Scene Two locked" height="255px" width="340px"/></li>
    <img id="banner"
    src="Images/crime-scene-banner.png" 
    height="5px"
    width="900px"/>
<h2 id="locked">Act Two</h2>
            <li id="navilockedl"><img src="Images/Scene-three-locked.png" alt="Scene three locked" height="255px" width="340px"/></li>
    <img id="arrow"
    src="Images/Right-Arrow.png" 
    height="80px"
    width="120px"/>
            <li id="navilockedr"><img src="Images/Scene-four-locked.png" alt="Scene four locked" height="255px" width="340px"/></li>
    <img id="banner"
    src="Images/crime-scene-banner.png" 
    height="5px"
    width="900px"/>
<h2 id="locked">Act Three</h2>
            <li id="navilockedl"><img src="Images/Scene-five-locked.png" alt="Scene five locked" height="255px" width="340px"/></li>
    <img id="arrow"
    src="Images/Right-Arrow.png" 
    height="80px"
    width="120px"/>
            <li id="navilockedr"><img src="Images/Scene-six-locked.png" alt="Scene six locked" height="255px" width="340px"/></li>

        </ul>

我想知道是否有任何精通 JQuery 的人可以为我指明正确的方向,因为我不知道我的语法是否正确,或者我只是无法连接到“connect.php”。

4

1 回答 1

0
// This part makes no sense. What you are doing is creating an array with 
// one entry 'permission', then assigning that new array the value of 7. 
if (['permission'] = '7') 
{ 
    // This will always run because non-zero numbers are 'true'
}

// To illustrate this in a more verbose way...

// Create an array with one item, a string 'permission'
var x = new Array();
x.push( 'permission' );

// X is no longer an array, it is now a number
x = 7; 

if ( x ) 
{ 
    // This will always run because non-zero numbers are 'true'
}

除此之外,您还需要将显示逻辑上移至 ajax 回调,或将其包装在由成功回调调用的函数中。

于 2013-03-22T21:16:02.607 回答