这是我的jQuery ......
$.ajax({
type: 'POST',
url: 'http://adamscarter.co.uk/daily/facebook/savefbprofile.php',
data: {'fb_id': fb_id, 'fbusername': fbusername, 'location_id': location_id, 'gender': gender},
beforeSend: function() {
console.log('Before send: ' + fb_id, fbusername, location_id, gender);
},
success: function(data) {
console.log('saveFbProfile post ajax success');
console.log(data);
}
});
...这是我的PHP ......
<?php
session_start();
include('dbcon.php');
$gender = substr($_POST['gender'], 0, 1);
$fb_id = $_POST['fb_id'];
$location_id = $_POST['location_id'];
$fbusername = $_POST['fbusername'];
//Set session vars
$_SESSION['gender'] = $gender;
$_SESSION['fb_id'] = $fb_id;
$_SESSION['location_id'] = $location_id;
$_SESSION['fbusername'] = $fbusername;
if (isset($_SESSION['userid'])) {
mysql_select_db('users', $GLOBALS['conInsert']);
$sql = "UPDATE user_fb_details SET gender = '". $gender. "', fb_id = '". $fb_id. "', location_id = '". $location_id. "', username = '". $fbusername. "' WHERE user_id = '". $_SESSION['userid']. "'";
mysql_query($sql, $GLOBALS['conInsert']);
}
?>
我的代码中有错误吗?当我记录变量时,它们都具有正确的值,但我只是得到一个'parseerror'。
答案 0 :(得分:1)
听起来jQuery可能会尝试将POST的结果解析为JSON响应而失败,因为它不是JSON。您可能希望将dataType设置为'text'
,或者从PHP返回不同的Content-Type
。
您肯定希望通过一些mysql_real_escape_string
或参数化查询修复危险的SQL注入漏洞。