我是JQuery中的新成員。我已經設法從php腳本將數據返回給JQuery,但是現在,當我將顯示從php腳本返回的消息顯示給用戶時,我看到消息<!--Separate connection with sessions -->
,並且我只想使用alert()向用戶顯示我的消息。JQuery從php文件返回數據
- 有人可以解釋這是什麼意思?
- 如何避免它顯示到警報框?
PHP代碼:
<?php
include "initialize.php";
if(empty($_POST) === false){
global $con;
$message = "";
$email = trim($_POST["email"]);
if(isSubscribed($email) === false){
$message = "Thank you for subscribing to our latest updates";
mysqli_query($con,"INSERT INTO subscribers(email) VALUES('".$email ."')");
}
else{
$message = "You already subscribed.";
}
echo $message;
}
?>
jQuery代碼:
$(function() {
$('#frms').on('submit', function (e) {
var email = $("#email").val();
if (!validateEmail(email)) {
alert('Error: Make sure you provided a valid email address');
}
else {
$.ajax({
type: 'post',
url: 'initialize/subscribe.php',
data: $('#frms').serialize(),
success: function (data) {
alert(data);
}
});
}
e.preventDefault();
});
});
'這是什麼意思' - 什麼? –