JavaScript passing the Value to php query
this is my first post here and hopefuly someone will help me fix this problem. I have this mysql query:
$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
";
and follwing 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>
now the problem is that when I inside form press submit button the Value "dating" from mysql query is not passed on acebook_style_ajax_more.php page using above JavaScript and Im getting empty value passed. What I need to change inside JS code to make it work?
Thanks
Use firebug or chrome developer extension to see the xhr request being posted through your javacript to the php code. First of all see that it might be that your selectors didnt pick up the values from the html. If the xhr is fine than go to your php and try echoing the request params. Hope this helps.
- for your actually are using get method replace ajax with get function
- put your query string in a data structure
it is easier to retrieve value in a variable var lastid= $(".postitem:last").attr("dating") || '';
$.get("facebook_style_ajax_more.php", { lastid: lastid }
.success(... wahever...)
);
HTH
Ivo Stoykov
i think you might have a problem here.. try alerting the value of $(".postitem:last").attr("dating") and make sure it is getting passed to the php page
url: "facebook_style_ajax_more.php?lastid=" + $(".postitem:last").attr("dating")
also if you are trying to sent the value of field with id "dating" then it should be
url: "facebook_style_ajax_more.php?lastid=" + $("#dating").val()
ADDED: also your code code doesnt show where the facebook_style_ajax_more.php is processing the $_REQUEST["lastid"] and echoing something back for the ajax function to process.
精彩评论