2013-05-14 36 views
1

你好即時通訊從一個JavaScript教程的代碼很偉大的工作..它的評級明星系統,所以我可以問我的用戶,你的技能的東西,他們可以「回答」利用這種評級制度,....使用json捕獲數據使用json在PHP中進行查詢

,所以我需要‘追趕’該值。(使用JSON?或者這就是我一直在這裏閱讀),終於將其插入數據庫

我可以將這個值存儲在$ _SESSION中嗎?..因爲這會很好,因爲我使用步驟公式,每個步驟在會話中存儲變量,所以在最後一步我插入所有使用PHP在MySQL數據庫。你會看到數據已準備好發送蜜蜂:D多數民衆贊成在偉大的,但是,我怎麼捕捉它,並將它存儲在$ _SESSION。提前致謝!!

而且我Asume,我可以ASIGN ID或東西從一個頁面發送多個率,

這不是在代碼中指定,並與JavaScript的即時通訊非常糟糕的其實..(這就是爲什麼我問所有的智慧人stackoverlflow)

這是從這裏http://reignwaterdesigns.com/ad/tidbits/rateme/

/* 
Author: Addam M. Driver 
Date: 10/31/2006 
*/ 

var sMax; // Isthe maximum number of stars 
var holder; // Is the holding pattern for clicked state 
var preSet; // Is the PreSet value onces a selection has been made 
var rated; 

// Rollover for image Stars // 
function rating(num){ 
    sMax = 0; // Isthe maximum number of stars 
    for(n=0; n<num.parentNode.childNodes.length; n++){ 
     if(num.parentNode.childNodes[n].nodeName == "A"){ 
      sMax++; 
     } 
    } 

    if(!rated){ 
     s = num.id.replace("_", ''); // Get the selected star 
     a = 0; 
     for(i=1; i<=sMax; i++){  
      if(i<=s){ 
       document.getElementById("_"+i).className = "on"; 
       document.getElementById("rateStatus").innerHTML = num.title;  
       holder = a+1; 
       a++; 
      }else{ 
       document.getElementById("_"+i).className = ""; 
      } 
     } 
    } 
} 

// For when you roll out of the the whole thing // 
function off(me){ 
    if(!rated){ 
     if(!preSet){  
      for(i=1; i<=sMax; i++){  
       document.getElementById("_"+i).className = ""; 
       document.getElementById("rateStatus").innerHTML = me.parentNode.title; 
      } 
     }else{ 
      rating(preSet); 
      document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML; 
     } 
    } 
} 

// When you actually rate something // 
function rateIt(me){ 
    if(!rated){ 
     document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title; 
     preSet = me; 
     rated=1; 
     sendRate(me); 
     rating(me); 
    } 
} 

// Send the rating information somewhere using Ajax or something like that. 
function sendRate(sel){ 
    alert("Your rating was: "+sel.title); 
} 

回答

1

評級系統的代碼在sendRate()函數調用Ajax的PHP小號更換alert CRIPT。爲此,您需要使用ajax庫(如jQuery)將值發佈到您的服務器。 (見http://api.jquery.com/jQuery.post/

例子:

$.post('/path/to/php', {rating: sel.title}, function (data) { 
    alert('Saved, server responded with' + data); 
}); 
+0

非常感謝,但什麼趕在PHP $ _SESSION = {評級方式:sel.title)我知道它不是,我在想念着這部分 – 2013-05-14 04:39:25

+0

的瀏覽器將向服務器提交POST請求。所以你的php腳本會通過'$ _POST ['rating']'看到輸入。要將該值放入會話中:'$ _SESSION ['rating'] = $ _POST ['rating']' – timemachine3030 2013-05-14 04:42:47