简体   繁体   English

在外部php文件中使用jQuery

[英]Use jQuery in external php file

I have a php file that I load into another php file with jQuery. 我有一个php文件,我使用jQuery将其加载到另一个php文件中。 This works, but the moment I start using jQuery in the 'external file', I get ERROR 500. The reason I used this approach is because this is handy to refresh the data after an AJAX function. 这是可行的,但是当我开始在“外部文件”中使用jQuery时,出现ERROR500。之所以使用这种方法,是因为在AJAX函数之后,这很方便刷新数据。

This I have: 我有:

test.php: test.php:

    <script type="text/javascript" src="js/modernizr.custom.29473.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script>
        $(function () {
            $(document).tooltip({
                items: ".plupic , .ingr",
                content: function() {
                    var element = $( this );
                    if ( element.is( ".plupic " ) ) {
                        var src = element.attr('src');
                        return "<img src='" + src + "' style='max-height: 300px; max-width: 300px;'>";
                    }
                    if ( element.is( ".ingr" ) ) {
                        var txt = element.text();
                        return txt;
                    }
                }
            });
            $('#kasticket').load('cart.php');
        });
    </script>
</head>
<body>
    <div class="container">
    <div id="kasticket"></div><!-- Load data with jQuery-->

cart.php: cart.php:

I just do a select from the database and write some data to a table with echo(); 我只是从数据库中进行选择,然后使用echo()将一些数据写入表中; This works perfectly, but the moment I want to use jQuery, I goes all wrong...(I know this for sure because the jQUery works in a local html file and putting this line in comment makes my php working again) 这完美地工作了,但是当我要使用jQuery时,我全错了...(我肯定知道这一点,因为jQUery在本地html文件中工作,并将此行放入注释中使我的php重新工作)

 echo("
     <script>
        jQuery(document).ready(function() {
            if($('#L$MyAant').width() < 70) {
                $('.TR1$MyAant').show();
                $('.TR2$MyAant').hide();
            }else{
                $('.TR2$MyAant').show();
                $('.TR1$MyAant').hide();
            }
        });
     </script>
 ");

I have no idea what I'm doing wrong. 我不知道我在做什么错。

If its any help: http://www.itreflex.be/TestAcc/test.php (with currently the jQuery line in comment). 如果有帮助,请访问: http : //www.itreflex.be/TestAcc/test.php (当前在jQuery行中有注释)。

And this is cart.php , exported to txt, it was to long to paste here. 这是cart.php ,已导出到txt,很久没有粘贴到这里了。

hard to tell without the full source code but I have got a couple of ideas: 没有完整的源代码很难说,但是我有两个想法:

First Error 500 should be the HTTP code for internal server error, which basically means that the error lies on the server, then on the PHP side. First Error 500应该是内部服务器错误的HTTP代码,这基本上意味着该错误位于服务器上,然后在PHP端。

Could it be possible that you are mixing up PHP and jQuery on some of your other statements not posted here? 您是否有可能在未在此处发布的其他一些语句上混淆了PHP和jQuery?

Second, you missed a single quote on your line 其次,您错过了一行单引号

$('#kasticket').load(cart.php');

In your cart.php remove the brackets after echo ... For example 在您的cart.php中,在回声后删除括号。例如

echo "<script>
    jQuery(document).ready(function() {
        if($('#L$MyAant').width() < 70) {
            $('.TR1$MyAant').show();
            $('.TR2$MyAant').hide();
        }else{
            $('.TR2$MyAant').show();
            $('.TR1$MyAant').hide();
        }
    });
 </script>";

Try this above line in your cart.php and see if that works. 在cart.php中的上面一行尝试一下,看看是否可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM