I have a form that submits data to a file called 'submit_link.php'. To submit the entered form values I am using this function with 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;
}
This is the file 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;
Now my problem is that I want the last three variables $link_id, $referral_link and $step2 returned from the server via json. How do I do this? How can I use the json-encoded data inside of my function submitLink() I posted above? How can I access each of the objects stored inside the json-data?