首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Ajax和Jquery修改Css值,基于Mysql行

使用Ajax和Jquery修改Css值,基于Mysql行
EN

Stack Overflow用户
提问于 2013-03-22 20:59:22
回答 1查看 277关注 0票数 0

所以我一直在这个系统上工作,当你在Mysql上的权限表中得到一个新的数字时,会自动更新一个场景选择页面。我有用于登录的Php和用于获取members表权限行中的数字的Php,它们运行良好。

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

connect.php :

代码语言:javascript
运行
复制
<?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:

代码语言:javascript
运行
复制
<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>   

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

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

#Scene1 :

代码语言:javascript
运行
复制
    <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‘。

EN

回答 1

Stack Overflow用户

发布于 2013-03-22 21:16:02

代码语言:javascript
运行
复制
// 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回调,或者将其封装到一个由成功回调调用的函数中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15579748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档