Answer the question
In order to leave comments, you need to log in
How to modify the phrase generator so that they are loaded via ajax?
Hello! There is this code
<?php
//Генерируем фамилию
$famtxt = file('comments.txt');
$famstr = $famtxt[ array_rand($famtxt) ];
unset($famtxt);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<title>Генератор</title>
<meta name="keywords" content="генератор" />
<meta name="description" content="Генератор" />
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<div class="wrapper">
<main class="content">
<div class="ribbon"><div class="ribbon-stitches-top"></div><strong class="ribbon-content"><h1>Генератор</h1></strong><div class="ribbon-stitches-bottom"></div></div>
<div class="gendata">
<div class="form-group">
<?php echo $famstr; ?>
</div>
<button onClick='parent.location="javascript:location.reload()"' class="btn btn-success">Хочу другую фразу</button>
</div>
</main>
</div>
Answer the question
In order to leave comments, you need to log in
1. It is better to put the PHP code in a separate file, write there:
<?php
if(isset($_POST['fam']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$famtxt = file('comments.txt');
return $famtxt[array_rand($famtxt)];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question