I'm trying to use the value sent by the AJAX request and echo it on a page. Here is how I did the AJAX on the first page (account.php):
account.php
$(document).on('click', 'div#demo', function(){
var id = $(this).attr('data-id');
$.ajax({
url: 'view.php',
type: 'get',
data: {id : id},
success: function(data) {
console.log(data);
}
});
});
Note: From account.php the user is navigated away when she/he clicks on an a href tag. That a href tag actually holds the unique ID what I use to pass to view.php within a div with ID of #ad. Also I'm using Bootstrap that's why I pass data-id = value.
I'm sure the AJAX works perfectly as the Console (F12) shows me that the request has been sent and the value what I used also got passed and the HTML uses it but it does not appear on the actual page so I can only see it in the browser's console. I found similar questions to mine but there were no exact answers to solve the problem. The other file looks like this:
view.php
<?php
require_once 'config.php';
$id = $_GET['id'];
$geturl = $conn->query("SELECT title, url FROM table1 WHERE id='$id'");
$url = mysqli_fetch_row($geturl);
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div class="container">
<iframe class="embed-responsive-item" src="<?php echo ($url[1]); ?>"></iframe>
</div>
</body>
</html>
So I would like to place an unique URL into an iframe after I get the value passed by AJAX and use that variable to do my SQL SELECT statements. After it succeed (because it does as it shows in the Console) I assign the SQL result-set to a variable and use that to give the value of the iframe. But if I click on an a href from account.php I'm navigated to view.php and I see only a blank iframe meanwhile the Console exactly shows that the iframe has the source what I want it to have.
I tried json_encode with the str_replace function but it does not work. I have also tried mixing encode and decode like
$enc = json_encode($row[1]);
$dec = json_decode($row[1]);
// and set the iframe src to $dec but still does not work.
Thanks for suggestions, appreciate your time!
UPDATE: I do not want to callback a function from the view.php, so I don't want to set the success: function(response) in AJAX to have a response from the sent request. I only want to use the passed variable on the view.php page, actually to echo it out after I ran my SQL stuff.