Ajax在php语句中不起作用。

时间:2022-11-22 21:28:43

getsubcat.php

getsubcat.php

<?php
include("config.php");
error_reporting(0);
 $checkedValue=$_GET['checkedValue']; 
$options= "";
$s=mysql_query("SELECT * FROM `sub_category` INNER JOIN `category` on sub_category.cat_id=category.cat_id where category.cat_name='$checkedValue'");
         while($rows=mysql_fetch_array($s))
         {
             $subcategory=$rows['sub_cat_name'];

             echo '<input name="sub_category" type="checkbox" class="checkbox_check1" onclick="select_subcatinfo('.$subcategory.')" id="checkbox_check1'.$subcategory.'" value="'. $subcategory.'" >&nbsp;'.$subcategory.'<br /><br />';

         }

         ?> 

This is my php coding which ll be loaded through ajax in another page.. Below is my ajax script.

这是我的php代码,将在另一个页面中通过ajax加载。下面是我的ajax脚本。

Ajax Script

Ajax脚本

function select_subcatinfo(name)
{
    $("#wait").css("display","block");
    var checkedValue1 = name;
    if( $("#checkbox_check1"+name).is(':checked') ) 
    {
        var xmlhttp;
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                $("#wait").css("display","none");
                data = xmlhttp.responseText.split("[BRK]");
                document.getElementById("DisplaySubcat").innerHTML = data[0]+" "+data[1];

            }
        }
        xmlhttp.open("GET","getSubcatValue.php?checkedValue1="+checkedValue1,true);
        xmlhttp.send();
    }
    else
    {
        $("#wait").css("display","none");   
    }        
}
</script>

But inside that echo statement this function is not working.. any help here . thankss

但在echo语句中,这个函数不起作用。任何帮助。谢谢

2 个解决方案

#1


3  

Don't use inline Javascript, use jQuery to bind the event handler:

不要使用内联Javascript,使用jQuery绑定事件处理程序:

$(document).ready(function() {
    $(".checkbox_check1").click(function() {
        if (this.checked) {
            $("#wait").show();
            $.get('getSubcatValue.php', { checkedValue1: this.value }, function(response) {
                var data = response.split('[BRK]');
                $("#DisplaySubcat").text(data[0] + ' ' + data[1]);
                $("#wait").hide();
            });
        }
    });
});

#2


0  

I'm really not trying to answer this...just cleaned up the op's PHP

我真的不想回答这个问题……刚刚清理了op的PHP

<?php
require("config.php");
error_reporting(0);
$checkedValue = $_REQUEST['checkedValue']; 
$options = "";
$s=mysql_query("SELECT * FROM `sub_category` INNER JOIN `category` on   sub_category.cat_id=category.cat_id where category.cat_name='$checkedValue'");
while($rows=mysql_fetch_array($s))
    { 
        $subcategory=$rows['sub_cat_name'];
        echo '<div><input name="sub_category" type="checkbox" class="checkbox_check1" onclick="select_subcatinfo('.$subcategory.')" id="checkbox_check1'.$subcategory.'" value="'. $subcategory.'" >&nbsp;'.$subcategory.'<br /><br /></div>';
    }
?> 

#1


3  

Don't use inline Javascript, use jQuery to bind the event handler:

不要使用内联Javascript,使用jQuery绑定事件处理程序:

$(document).ready(function() {
    $(".checkbox_check1").click(function() {
        if (this.checked) {
            $("#wait").show();
            $.get('getSubcatValue.php', { checkedValue1: this.value }, function(response) {
                var data = response.split('[BRK]');
                $("#DisplaySubcat").text(data[0] + ' ' + data[1]);
                $("#wait").hide();
            });
        }
    });
});

#2


0  

I'm really not trying to answer this...just cleaned up the op's PHP

我真的不想回答这个问题……刚刚清理了op的PHP

<?php
require("config.php");
error_reporting(0);
$checkedValue = $_REQUEST['checkedValue']; 
$options = "";
$s=mysql_query("SELECT * FROM `sub_category` INNER JOIN `category` on   sub_category.cat_id=category.cat_id where category.cat_name='$checkedValue'");
while($rows=mysql_fetch_array($s))
    { 
        $subcategory=$rows['sub_cat_name'];
        echo '<div><input name="sub_category" type="checkbox" class="checkbox_check1" onclick="select_subcatinfo('.$subcategory.')" id="checkbox_check1'.$subcategory.'" value="'. $subcategory.'" >&nbsp;'.$subcategory.'<br /><br /></div>';
    }
?>