我有一个将数据提交到名为“submit_link.php”的文件的表单。要提交输入的表单值,我将这个函数与 jQuery 一起使用:
function submitLink() {
if ($('#lnk_email2').val().length == 0) {
$.ajax({
type:'POST',
url: '<?php echo $setting['site_url'] .'/';?>includes/misc/submit_link.php',
data:$('#add_link_form').serialize(),
beforeSend: function() {
$('#lnk_exch_ini').remove();
$('#loader_submit').css('display', 'block').html("<img src='<?php echo $setting['site_url'] . $setting['template_url'] .'/';?>images/loader.gif' />");
},
error: function() {
},
success: function() {
$('#loader_submit').remove();
},
complete: function() {
$('#lnk_exch_content').load('includes/forms/add_link_form2.php');
}
});
} else {
//do nothing
}
return false;
}
这是文件 submit_link.php:
if ($user['login_status'] == 1) {
$email = $user['email'];
$submitter = $user['id'];
}
else {
$submitter = 0;
}
if (strpos($url, "http://") === false) {
$url = 'http://'.$url;
}
mysqli_query($con, "INSERT INTO ava_links SET name='$anchor', url = '$url', description = '$description', sitewide = 1, published = 0,
submitter = $submitter, submitter_email = '$email'") or die (mysqli_error($con));
$link_id = mysqli_insert_id($con);
$referral_link = $setting['site_url'].'/?r='.$link_id;
$step2 = LINK_EXCHANGE_STEP2;
现在我的问题是我想要通过 json 从服务器返回的最后三个变量 $link_id、$referral_link 和 $step2。我该怎么做呢?如何在上面发布的函数 submitLink() 中使用 json 编码的数据?如何访问存储在 json-data 中的每个对象?