2017-10-17 98 views
0

瞭解我,我可能做錯了什麼,但我看看如何解析數據從Javascript到PHP看起來像使用Ajax,它看起來不錯,但它不想通過發送數據並更新它我的數據庫。Ajax無法正確解析數據?

發生的只是一個對話框,裏面沒有任何東西。

AJAX:

$.ajax({ 
     url: 'updateCredits.php', 
     type: 'GET', 
     data: { 
      credits: totalcash 
     }, 
     success: function(data){ 
      alert(data); 
     } 
    }); 

PHP:

<?php 

require 'steamauth/steamauth.php'; 
include ('steamauth/userInfo.php'); 
include('mysql/config.php'); 

if(isset($_SESSION['steamid'], $_GET["credits"])) { 
    $credits = $_GET['credits']; 
    mysqli_query($db,"UPDATE set credits = credits + '".$credits."' WHERE steamid = '".$steamprofile['steamid']."'"); 
} else { 
echo 'An Error has occurred, this is either due to you not being logged in or something went wrong!'; 

} 

?> 
+1

你期望發生的?你沒有在成功上回應任何事情。 另外你的代碼是非常非常非常脆弱的[SQL注入](https://www.owasp.org/index.php/SQL_Injection) – ntzm

+0

側面說明:您應該使用PUT如果更新操作 –

+0

這是工作正常。代碼中的空警報意味着,在數據庫中最可能沒有錯誤和數據。 –

回答

0

你是不是從PHP返回任何東西片斷成功

<?php require 'steamauth/steamauth.php'; 
include ('steamauth/userInfo.php'); 
include('mysql/config.php'); 
if(isset($_SESSION['steamid'], $_GET["credits"])) 
{ 
    $credits = $_GET['credits']; mysqli_query($db,"UPDATE set credits = credits + '".$credits."' WHERE steamid = '".$steamprofile['steamid']."'"); 
echo 'Success fully updated'; 
} else { echo 'An Error has occurred, this is either due to you not being logged in or something went wrong!'; } ?>