2017-10-03 1 views
-1

나는 자바 스크립트 코드를 가지고 있는데, 나는이 코드를 온라인으로 구입한다. 코드는 스핀 휠 게임을 실행합니다. 그리고 나는 데이터베이스에 회전 속도계 결과를 저장하고 싶습니다. 실제로 js 코드는 이미 결과 함수를 제공하지만 mysql 데이터베이스에 결과 함수를 저장하는 방법을 알지 못했습니다.자바 스크립트 콘솔을 MySQL 데이터베이스에 저장하는 방법

//Usage 
 

 
//load your JSON (you could jQuery if you prefer) 
 
function loadJSON(callback) { 
 

 
    var xobj = new XMLHttpRequest(); 
 
    xobj.overrideMimeType("application/json"); 
 
    xobj.open('GET', './wheel_data.php', true); 
 
    xobj.onreadystatechange = function() { 
 
    if (xobj.readyState == 4 && xobj.status == "200") { 
 
     //Call the anonymous function (callback) passing in the response 
 
     callback(xobj.responseText); 
 
    } 
 
    }; 
 
    xobj.send(null); 
 
} 
 

 
//your own function to capture the spin results 
 
function myResult(e) { 
 
    //e is the result object 
 
    console.log('Spin Count: ' + e.spinCount + ' - ' + 'Win: ' + e.win + ' - ' + 'Message: ' + e.msg); 
 

 
    // if you have defined a userData object... 
 
    if(e.userData){ 
 
     
 
     console.log('User defined score: ' + e.userData.score) 
 

 
    } 
 

 
    //if(e.spinCount == 3){ 
 
    //show the game progress when the spinCount is 3 
 
    //console.log(e.target.getGameProgress()); 
 
    //restart it if you like 
 
    //e.target.restart(); 
 
    //} 
 

 
} 
 

 
//your own function to capture any errors 
 
function myError(e) { 
 
    //e is error object 
 
    console.log('Spin Count: ' + e.spinCount + ' - ' + 'Message: ' + e.msg); 
 

 
} 
 

 
function myGameEnd(e) { 
 
    //e is gameResultsArray 
 
    console.log(e); 
 
    TweenMax.delayedCall(5, function(){ 
 
    /*location.reload();*/ 
 
    }) 
 

 

 
} 
 

 
function init() { 
 
    loadJSON(function(response) { 
 
    // Parse JSON string to an object 
 
    var jsonData = JSON.parse(response); 
 
    //if you want to spin it using your own button, then create a reference and pass it in as spinTrigger 
 
    var mySpinBtn = document.querySelector('.spinBtn'); 
 
    //create a new instance of Spin2Win Wheel and pass in the vars object 
 
    var myWheel = new Spin2WinWheel(); 
 
    
 
    //WITH your own button 
 
    myWheel.init({data:jsonData, onResult:myResult, onGameEnd:myGameEnd, onError:myError, spinTrigger:mySpinBtn}); 
 
    
 
    //WITHOUT your own button 
 
    //myWheel.init({data:jsonData, onResult:myResult, onGameEnd:myGameEnd, onError:myError); 
 
    }); 
 
} 
 

 

 

 
//And finally call it 
 
init();

누군가가 튜토리얼 또는 내 문제에 대한 몇 가지 기준을 제공하는 데 도움이 있습니다 : 여기

코드인가? thankyou.

+0

변환 JS 코드'와 데이터베이스에 저장하고 인출 할 때 해당 데이터베이스에서 다음 사용자'링크 - CDN에 의해 JSON.parse (데이터베이스에서)', 실제 js 코드 용 –

답변

0

아약스는 여전히 당신을 위해 작동하지 않는 경우 나, 서버 단에서의 당신의 사용 PHP를 가정하고 있지만 서버 스크립트 사용자 정의 할 수 있습니다 : 당신은
추가 JQuery와 스크립트에 .php 자바 스크립트에서 데이터를 공유 할 Ajax를 필요

을 CONSOLE.LOG 문 사용 후 https://code.jquery.com/
:`JSON.stringify (jscode)를 사용하여 문자열

$.ajax({ 
     type: 'post', 
     url: "sample.php", // replace your with .php file which will receive data 
     data: { 'spinCount': e.spinCount, 'Win': e.win }, 

     success: function(result){ 

      console.log(result); // Do what you want if data successfully trasfered. 
     } 
}); 




if(isset($_POST['Win'] && $_POST['spinCount'])){ 
    // store these in database 
    $_POST['Win']; 
    $_POST['spinCount'];  
} 
관련 문제