我有简单的ajax代码:
function showMe(data) {
$("body").append();
if(data.success == true) {
$("body").append("<img src="+data.data.link+" height=180 /><br /><a href="+data.data.link+">"+data.data.link+"</a>");
$.ajax ({
type: "POST",
url: "sql.php",
data: "y=+data.data.link+",
});
我需要获取'+ data.data.link +'值并发送到mysql db,但它发送data.data.link而不是真正的链接。 如何获得真正的价值并发送到数据库? 这是sql.php:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : 'forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include("$phpbb_root_path/includes/functions_user.php");
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewtopic');
include "forum/config.php";
$link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd");
$db_selected = mysql_select_db("$dbname", $link);
$y = @$_POST['y'];
$date = date('d.m.y');
$name = $user->data['username'];
mysql_query("INSERT INTO `gallery` (name, createdate, piclink) VALUES('$name', '$date', '".$y."')");
unlink("gallery/$imagename");
?>
感谢您的帮助:)
答案 0 :(得分:3)
将数据作为对象发送(干净且可读)而不是字符串..
试试这个
data: {'y':data.data.link},
答案 1 :(得分:0)
您没有透露“data.data.link”的来源,但主要问题是在ajax代码中:
$.ajax ({
type: "POST",
url: "sql.php",
data: "y=\""+data.data.link+"\"",
});
对变量(data.data.link
)的引用不得在引号中进行评估。