繁体   English   中英

JavaScript将Value传递给php查询

[英]JavaScript passing the Value to php query

这是我在这里的第一篇文章,希望有人能帮助我解决此问题。 我有这个mysql查询:

$query_history = "
            SELECT ProductProvider AS NameSS, type, StoreOpinionDate AS dating
            FROM cd_stores 
            WHERE UserFID = '".$row_Profile['UserFID']."' 

            UNION ALL

            SELECT BrandName AS NameSS, type, BrandOpinionDate AS dating 
            FROM cd_brandopinions
            WHERE UserFID = '".$row_Profile['UserFID']."'

            UNION ALL

            SELECT CommentTitle AS NameSS, type, CommentDate AS dating 
            from cd_comments
            WHERE UserFID = '".$row_Profile['UserFID']."'

            UNION ALL

            SELECT brands.ProductBrand AS NameSS, type, date AS dating 
                from brandtrack INNER JOIN brands 
            WHERE UserFID = '".$row_Profile['UserFID']."' and brandtrack.BrandID = brands.BrandID

            ORDER BY dating DESC
            LIMIT 9
";

和以下javascript:

<script type="text/javascript" src="../admin/config/js/jquery/jquery-1.3.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("#loadmorebutton").click(function (){
                $('#loadmorebutton').html('<img src="facebook_style_loader.gif" />');
                $.ajax({
                    url: "facebook_style_ajax_more.php?lastid=" + $(".postitem:last").attr("dating"),
                    success: function(html){
                        if(html){
                            $("#postswrapper").append(html);
                            $('#loadmorebutton').html('Load More');
                        }else{
                            $('#loadmorebutton').replaceWith('<center>No more posts to show.</center>');
                        }
                    }
                });
            });
        });
    </script>

现在的问题是,当我在表单内部按下提交按钮时,使用上述JavaScript的acebook_style_ajax_more.php页面上没有传递来自mysql查询的“约会”值,并且Im传递了空值。 我需要在JS代码中进行哪些更改才能使其正常工作?

谢谢

使用firebug或chrome开发人员扩展,查看通过您的Javacript发布到php代码的xhr请求。 首先,您可能会发现选择器没有从html中获取值。 如果xhr没问题,那就去您的PHP并尝试回显请求参数。 希望这可以帮助。

我认为您可能在这里有问题..尝试提醒$(“。postitem:last”)。attr(“ dating”)的值,并确保将其传递到php页面

    url: "facebook_style_ajax_more.php?lastid=" + $(".postitem:last").attr("dating")

另外,如果您尝试发送ID为“ dating”的字段的值,则应为

   url: "facebook_style_ajax_more.php?lastid=" + $("#dating").val()

添加:您的代码也没有显示facebook_style_ajax_more.php在哪里处理$ _REQUEST [“ lastid”]并回显某些内容以供ajax函数处理。

  1. 因为您实际上正在使用get方法使用get函数替换ajax
  2. 将查询字符串放入数据结构

在变量var lastid = $(“。postitem:last”)。attr(“ dating”)||中检索值更容易。 '';

$.get("facebook_style_ajax_more.php", { lastid: lastid } 
   .success(... wahever...)
);

高温超导

伊沃·斯托伊科夫(Ivo Stoykov)

暂无
暂无

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

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