Javascript jQuery';s$.get()仅在设置了function()参数时有效
我正在尝试构建一个web应用程序,因此我希望使用jqueryJavascript jQuery';s$.get()仅在设置了function()参数时有效,javascript,php,jquery,html,web-applications,Javascript,Php,Jquery,Html,Web Applications,我正在尝试构建一个web应用程序,因此我希望使用jquery$.get函数将值从php文件传递到html文件 虽然$.get(“url/file.php”)工作正常,但是$.get(“url/file.php”,函数(数据){alert(“test123”);})的内部函数不起作用 我从w3schools找到了一个示例脚本,它运行良好,我试图用我自己的文件(url/file.php)替换示例文件,但内部函数不起作用,我还尝试用脚本中的示例文件替换我的文件,但内部函数同样不起作用 编辑: 这是我的
$.get
函数将值从php文件传递到html文件
虽然$.get(“url/file.php”)
工作正常,但是$.get(“url/file.php”,函数(数据){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>
阵列回顾
p{显示:无}
输入[type=text],输入[type=password]{填充:5px;边框:2px实心#ccc;
-webkit边界半径:5px;
边界半径:5px;
}
输入[type=text],输入[type=password]:焦点{边框颜色:#333;}
输入[type=submit]{填充:5px15px;背景:#5A57B2;边框:0无;
光标:指针;
-webkit边界半径:5px;
边界半径:5px;}
斯托伊克西先生{
颜色:白色;
}
#艾科纳{
背景图片:url(“owl.png”);
背景重复:无重复;
背景位置:中上;
身高:11.28%;
宽度:99%;
}
身体{
高度:470px;
宽度:330px;
背景图片:url(“bi2.png”);
背景重复:重复;
}
#全部,第1页{
身高:100%;
宽度:100%;
}
#演示{
左缘:6%;
利润率最高:1%;
颜色:#FCE94D;
}
#演示1{
左缘:6%;
利润率最高:0%;
颜色:#FCE94D;
}
#表格1{
利润上限:-2%;
身高:42.55%;
宽度:75.76%;
}
#表格2{
利润率最高:2%;
身高:30%;
宽度:75.76%;
}
window.onload=函数(){
document.getElementById(“ii”).style.height=window.innerHeight+“px”;
document.getElementById(“ii”).style.width=window.innerWidth+“px”;
document.getElementById(“整个”).style.height=window.innerHeight+“px”;
document.getElementById(“整个”).style.width=window.innerWidth+“px”;
};
$(文档).ready(函数(){
$(“#signupp”)。单击(函数(){
变量url=”http://giannisgoulias.co.nf/Connect/welcome.php?“+”name=“+$(“#name”).val()+”&password=“+$(“#password”).val()+”&email=“+$(“#email”).val();
$.get(url,函数(数据){alert('test');});
});
});
你好请注册!
用户名:
密码:
电子邮件:
登录!
用户名:
密码:
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>
问题出在php文件中-直接在浏览器中访问它,看看它输出了什么。您是否输出或回显了php文件中的任何内容?function(data)
中的变量data
只有在PHP发送输出时才会保存一个值。您需要发布更多的代码,以便我们可以看到导致问题的原因。或者您没有正确的路径。在浏览器开发工具中检查实际请求network@Steve我直接访问了我的浏览器,看到了我期望的字符串。