我正在尝试构建一个Web应用程序,所以我想将一个php文件中的值传递给一个带有jquery $.get
函数的html文件。
虽然$.get("url/file.php")
工作正常,但$.get("url/file.php",function(data){ alert("test123");});
的内部功能不起作用。
我从w3schools找到了一个示例脚本,它工作正常,我试图用我自己的文件(url/file.php
)替换样本的文件,内部函数不起作用,我也尝试用我的文件替换我的脚本中的示例文件再次内部函数将无法正常工作。
编辑: 这是我的代码。我想做的是通过单击注册按钮将用户名,密码,电子邮件发送到php文件,以便在数据库中注册用户并从php文件中获取一个字符串
包含javascript的inde6.html文件是:
<html>
<head>
<title>Array Review</title>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<link href="css/index2.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<style type="text/css">
p {display:none}
input[type=text],input[type=password] {padding:5px; border:2px solid #ccc;
-webkit-border-radius: 5px;
border-radius: 5px;
}
input[type=text],input[type=password]:focus {border-color:#333; }
input[type=submit] {padding:5px 15px; background:#5A57B2; border:0 none;
cursor:pointer;
-webkit-border-radius: 5px;
border-radius: 5px; }
.stoixisi {
color:white;
}
#eikona {
background-image: url("owl.png");
background-repeat: no-repeat;
background-position: center top;
height:11.28%;
width:99%;
}
body {
height:470px;
width:330px;
background-image:url("bi2.png");
background-repeat:repeat;
}
#whole,#page1 {
height:100%;
width:100%;
}
#demo {
margin-left:6%;
margin-top:1%;
color:#FCE94D;
}
#demo1 {
margin-left:6%;
margin-top:0%;
color:#FCE94D;
}
#form1 {
margin-top:-2%;
height:42.55%;
width:75.76%;
}
#form2 {
margin-top:2%;
height:30%;
width:75.76%;
}
</style>
<script>
window.onload= function () {
document.getElementById("ii").style.height=window.innerHeight+"px";
document.getElementById("ii").style.width=window.innerWidth+"px";
document.getElementById("whole").style.height=window.innerHeight+"px";
document.getElementById("whole").style.width=window.innerWidth+"px";
};
$(document).ready(function(){
$("#signupp").click(function(){
var url="http://giannisgoulias.co.nf/Connect/welcome.php?"+"name="+$("#name").val()+"&password="+$("#password").val()+"&email="+$("#email").val();
$.get(url,function(data){alert('test');});
});
});
</script>
</head>
<body id="ii">
<div data-role="page" data-control-title="Home" id="page1">
<div id="whole">
<div id="eikona"></div>
<h2 id="demo1">Hi!Please Sign Up!</h2>
<p>
<form action="inde6.html" method="post" id="form1">
<div class="stoixisi">Username:</div> <input type="text" name="name" id="name"><br>
<div class="stoixisi">Password:</div> <input type="password" name="password" id="password"><br>
<div class="stoixisi">E-mail:</div> <input type="text" name="email" id="email"><br>
<input type="Submit" value="Sign Up" id="signupp">
</form>
<h2 id="demo1">Sign In!</h2>
<form action="signin.php" method="post" id="form2">
<div class="stoixisi">Username:</div> <input type="text" name="name"><br>
<div class="stoixisi">Password:</div> <input type="password" name="password"><br>
<input type="Submit" value="Sign In" onclick="signin()">
</div>
</form>
</p>
</body>
</html>
和php文件是
<html>
<head></head>
<body>
<p>
<?php
$dbhost=****;
$dbuser=*****;
$dbpass=*****;
$db=*****;
$conn= mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($db);
mysql_query ("set character_set_results='utf8'");
$nname = mysql_real_escape_string($_GET["name"]);
$ppassword = mysql_real_escape_string($_GET["password"]);
$mmail=mysql_real_escape_string($_GET["email"]);
$query2="SELECT User_Name FROM table1 WHERE User_Name IN ('$nname')";
$query3="SELECT User_Mail FROM table1 WHERE User_Mail IN ('$mmail')";
$result2=mysql_query($query2);
$result3=mysql_query($query3);
$num_rows = mysql_num_rows($result2);
$num_rows2 = mysql_num_rows($result3);
$user_exists=0;
$mail_exists=0;
if ($num_rows>0 ) {
$user_exists=1;
}
if ($num_rows2>0) {
$mail_exists=1;
}
if ($user_exists==0 && $mail_exists==0)
{
$query1="INSERT INTO table1
(User_Name,User_Password,User_Mail) VALUES ('$nname','$ppassword','$mmail')";
$result1=mysql_query($query1);
$queryy="INSERT INTO table2
(UserName) VALUES ('$mmail')";
$resultt=mysql_query($queryy);
$queryyl="INSERT INTO NGames
(player,gnumber) VALUES ('$mmail',0)";
$resulttl=mysql_query($queryyl);
}
if ($user_exists==1 && $mail_exists==1) {
$out="Username and mail already exists!";
}
else if ($user_exists==1) {
$out= "This username already exists!";
}
else
{
if ($mail_exists==1) {
$out="This mail already exists!";
}
else {
$out="Sign in to play!";
};
}
echo $out;
?>
</p>
</body>
</html>