Ich erstelle eine Benachrichtigungsprüfung über AJAX und PHP.PHP-Variable aus AJAX senden
Ich habe eine Warnung erstellt, die "yep" oder "nein" hängt, wenn die Antwort empfangen wird, jedoch keine Warnung angezeigt wird.
Sende ich meine PHP-Variable korrekt?
PHP:
<?php
session_start();
if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
//Request identified as ajax request
//HTTP_REFERER verification
if($_SESSION['email'] == $_GET['email']) {
\t \t require_once 'connect.php';
\t \t \t /* FORM VARIABLES */
\t \t \t $email \t \t \t = strtolower($_GET['email']);
\t \t \t try
\t \t \t {
\t \t \t \t $stmt = $pdo->prepare("SELECT * FROM notifications WHERE to=:email");
\t \t \t \t $stmt->execute(array(":email"=>$email));
\t \t \t \t $count = $stmt->rowCount();
\t \t \t \t echo $count;
\t \t \t }
\t \t \t catch(PDOException $e){
\t \t \t \t echo $e->getMessage();
\t \t \t }
\t \t
\t \t }
else {
header('Location: http://website.com');
}
}
else {
header('Location: http://website.com');
}
?>
AJAX:
\t \t \t <script>
\t \t \t \t function notificationCheck() {
\t \t \t \t \t
\t \t \t \t \t $.ajax({
\t \t \t \t \t \t url: 'website.com/page.php?email='<? echo $email ?>,
\t \t \t \t \t \t data: "",
\t \t \t \t \t \t success: function (data) {
\t \t \t \t \t \t \t
\t \t \t \t \t \t \t var bubification = data;
\t \t \t \t \t \t \t
\t \t \t \t \t \t \t if (bubification === 0) {
\t \t \t \t \t \t \t \t
\t \t \t \t \t \t \t \t window.alert("Yes");
\t \t \t \t \t \t \t \t
\t \t \t \t \t \t \t } else {
\t \t \t \t \t \t \t \t
\t \t \t \t \t \t \t \t window.alert("Nope");
\t \t \t \t \t \t \t \t
\t \t \t \t \t \t \t }
\t \t \t \t \t \t \t $('#profile-sidebar-responsive-notifcation-count').html(''+bubification+''); \t \t \t \t \t \t $('#profile-sidebar-notifcation-count').html(''+bubification+'');
\t \t \t \t \t \t }
\t \t \t \t \t });
\t \t \t \t }
\t \t \t \t $(document).ready(notificationCheck);
\t \t \t \t setInterval(notificationCheck, 10000);
\t \t \t </script>
Ich schätze Ihre URL ist falsch. Sie müssen es absolut machen (zB 'http: //website.com/page.php? ...' oder relativ (zB '/page.php? ...') –
ändern Sie Echo $ email?> Zu php echo $ email?> Wenn Sie erhalten 404 Fehler –
Sie haben Antworten unter –