2016-05-26 34 views
0

我需要得到下面的代码通过$ Bus_Account_ID和$ Usr_ID到包括文件rating2.php与AJAX传递到PHP包括

$Bus_Account_ID=733; 
    $Usr_ID=3; 

我不familar与AJAX所以在这里学习。 我认为,这是传递到包括行,但我不知道什么是与“attrVal”

data: 'postID='+attrVal+'&ratingPoints='+val, 
$(function() { 
    var value = "<?php echo $total_points ?>"; 

    $("#rating_star").codexworld_rating_widget({ 
     starLength: '5', 
     initialValue: value, 
     callbackFunctionName: 'processRating', 
     imageDirectory: 'images/', 
     inputAttr: 'postID' 
    }); 
}); 

function processRating(val, attrVal){ 
    $.ajax({ 
     type: 'POST', 
     url: 'rating2.php', 
     data: 'postID='+attrVal+'&ratingPoints='+val, 
     dataType: 'json', 
     success : function(data) { 
      if (data.status == 'ok') { 

       $('#avgrat').text(data.total_points); 
       $('#totalrat').text(data.rating_number); 
      }else{ 
       alert('Some problem occured, please try again.'); 
      } 
     } 
    }); 
} 

显示帖子ID仅3在上面,在这里所发生

<input name="rating" value="0" id="rating_star" type="hidden" postID="1" /> 

这就是被称为上包括文件

$postID = $_POST['postID']; /* BUSINESS ID */ 

如何调用$ Bus_Account_ID和$ Usr_ID?

+0

'数据:“帖子ID ='+ attrVal +'&ratingPoints ='+ val,'应该是这样的'data:{name:“John”,location:“Boston”}' –

+0

@FrayneKonok - 哈?名字:约翰?位置:波士顿? OP如何工作就好了(语法上) – Marcus

+0

将'data:'postID ='+ attrVal +'&ratingPoints ='+ val,'更改为'data:'postID ='+ attrVal +'&ratingPoints ='+ val +'&userID = <?php echo $ Usr_ID; ?>&busAccountID = <?php echo $ Bus_Account_ID; ?>','你可以分别使用'$ _POST ['userID']'和'$ _POST ['busAccountID']'访问'rating2.php'中的那些。看看这是怎么回事。 – Marcus

回答

1

你有问题路过此处的数据..,你需要保持这样的格式:data: { name: "John", location: "Boston" }

$.ajax({ 
     type: 'POST', 
     url: 'rating2.php', 
     data: 'postID='+attrVal+'&ratingPoints='+val, 

所以更改数据通过,

data: { postID: attrVal, ratingPoints: val, Usr_ID : "<?php echo $Usr_ID;?>", Bus_Account_ID : "<?php echo $Bus_Account_ID;?>" } 
+0

我确实改变:data:{postID: attrVal,ratingPoints:val},并且还将<?php $ Bus_Account_ID = 733;?> \t添加到正文中,它允许我传递$ Bus_Account_ID,但是如何添加$ Usr_ID来传递? – harkly

+0

所以你想通过useid和busaccid? –

+0

是的,传递2个变量$ Bus_Account_ID和$ Usr_ID,我有一个总线工作,有点卡住在Usr上。我没有得到这么多:数据:{postID:attrVal,ratingPoints:val,userID:3},它的工作原理,但我需要“3”是一个变量 – harkly