ajax发布在firebug中显示为红色 [英] ajax posting is shown as red color in firebug
本文介绍了ajax发布在firebug中显示为红色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我执行以下代码,那么我在提交表单时启用了firebug.In firebug,在控制台中post to login_submit.php显示为红色。我也没有得到任何响应。
<!DOCTYPE html>
< html>
< head>
< title>登录页面< / title>
< script type =text / javascriptsrc =js / jquery.min.js>
< / script>
< script type =text / javascriptsrc =js / scripts.js>
< / script>
< script type ='text / javascript'>
函数submit_login_form()
{
var action =login_submit.php;
$ .ajax(
{
url:'login_submit.php',
类型:'POST',
数据:$('#login ')。serialize(),
成功:函数(data_in)
{
alert(data_in);
if(data_in!== null&&!isEmpty(data_in) )&&(data_in).indexOf('VALIDATION_ERROR')!== -1)
{
var value = data_in.substr(data_in.indexOf('VALIDATION_ERROR'),data_in.indexOf( '| #END#'));
var array_str = value.split('|');
var id_val =#id_+ array_str [1] .trim();
show_error(id_val,array_str [2]);
} else
{
window.location.replace('jb_organization_regn_confirm.html');
}
}
}
);
返回false;
}
< / script>
< / head>
< body>
< form action =login_submit.phpid =login>
< h1> LOGIN< / h1>
Email< input value =name =user_emailid =user_login>< br>
密码< input value =name =pwdtype =passwordid =pwd_login>< br>
< input type =checkboxname =remember_me>保持登录状态< br>
< input type =submitvalue =loginonclick =submit_login_form()>
< / form>
< / body>
< / html>
以下是我的login_submit.php
<?php require'db.php'; ?>
<?php require'hopping_user_class.php'; ?>
<?php
$ error_op =START;
$ obj_shopping_login =新用户;
// $ obj_shopping_login-> shopping_user_name =;
$ obj_shopping_login-> shopping_user_pwd =;
$ obj_shopping_login-> shopping_user_email =;
$ obj_shopping_login-> remember_me =;
函数Collect_all_form_variables(){
global $ obj_shopping_login;
global $ error_op;
尝试{
$ obj_shopping_login-> shopping_user_email = $ _POST [user_email];
$ obj_shopping_login-> shopping_user_pwd = $ _POST [pwd];
if(isset($ _ POST ['remember_me'])&&
$ _POST ['remember_me'] =='yes'){
$ obj_shopping_login-> ; remember_me ='yes';
} else {
$ obj_shopping_login-> remember_me ='no';
}
} catch(Exception $ e){
echo'Error:'。 $ E->的getMessage();
$ error_op ='Collect_all_form_variables'。 $ error_op。 $ E->的getMessage();
}
}
function check_useremail_and_password($ current_user_email,$ current_user_pwd){
global $ error_op;
尝试{
global $ pdo; (从电子邮件用户中选择*WHERE UPPER(email)= UPPER(:current_user_email)AND pwd =:current_user_pwd );
//执行查询,用它们的真实值替换占位符
$ sth-> execute(array(
':current_user_email'=> trim($ current_user_email) ,
':current_user_pwd'=> current_user_pwd
));
if($ sth-> rowCount()> 0){
return true;
}
return false;
} catch(PDOException $ e){
echo'Error:'。 $ E->的getMessage();
$ error_op ='check_useremail_and_password'。 $ error_op。 $ E->的getMessage();
}
返回true;
}
函数validate_form_stage1(){
// alert(please);
$ required = array('user_email','pwd');
//循环字段名称,确保每个字段都存在并且不为空
$ error = false;
foreach($ $ as $ field){
if(empty($ _ POST [$ field])){
$ error = true;
休息;
}
}
如果($ error){
返回VALIDATION_ERROR | 。 $字段。 |值为必填|#END#;
} else {
returnSUCCESS;
}
}
函数process_request(){
global $ obj_shopping_login;
global $ error_op;
$ all_values_are_present = validate_form_stage1();
if(substr($ all_values_are_present,0,16)===VALIDATION_ERROR){
echo $ all_values_are_present;
返回false;
}
Collect_all_form_variables();
if(check_useremail_and_password()== true){
echoSuccess。 $ error_op;
} else {
echo失败。 $ error_op;
}
}
?>
解决方案
添加 var $ = jQuery
$ b
< script type ='text / javascript'>
var $ = jQuery;
//你的功能在这里......
< / script>
或
$(document).ready(function(){
//你的函数在这里...
});
推荐:
在关闭< body>
标签之前添加脚本,如...
<!DOCTYPE HTML>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< title>您的网站< / title>
< / head>
< body>
< header>
< / header>
< section>
< / section>
< aside>
< / aside>
< footer>
< / footer>
< script src =// ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js\"> ;</script>
< script> window.jQuery || document.write('your_local_here / jquery.js>< \ / script>')< / script>
< script src =custom.js>< / script>
< script>
//或这里
< / script>
< / body>
< / html>
If i execute the following code ,then i enabled the firebug.In firebug while submitting form ,in console the "post to login_submit.php" is shown as a red color.And i also didnt get any response too.
<!DOCTYPE html>
<html>
<head>
<title>Login page</title>
<script type="text/javascript" src="js/jquery.min.js">
</script>
<script type="text/javascript" src="js/scripts.js">
</script>
<script type='text/javascript'>
function submit_login_form()
{
var action = "login_submit.php";
$.ajax(
{
url: 'login_submit.php',
type: 'POST',
data: $('#login').serialize(),
success: function(data_in)
{
alert(data_in);
if (data_in !== null && !isEmpty(data_in) && (data_in).indexOf('VALIDATION_ERROR') !== -1)
{
var value = data_in.substr(data_in.indexOf('VALIDATION_ERROR'), data_in.indexOf('|#END#'));
var array_str = value.split('|');
var id_val = "#id_" + array_str[1].trim();
show_error(id_val, array_str[2]);
} else
{
window.location.replace('jb_organization_regn_confirm.html');
}
}
}
);
return false;
}
</script>
</head>
<body>
<form action="login_submit.php" id="login">
<h1>LOGIN</h1>
Email<input value="" name="user_email" id="user_login"><br>
Password<input value="" name="pwd" type="password" id="pwd_login"><br>
<input type="checkbox" name="remember_me">Stay Signed In<br>
<input type="submit" value="login" onclick="submit_login_form()">
</form>
</body>
</html>
The below one is my login_submit.php
<?php require 'db.php'; ?>
<?php require 'shopping_user_class.php'; ?>
<?php
$error_op = " START ";
$obj_shopping_login = new user;
//$obj_shopping_login->shopping_user_name = "";
$obj_shopping_login->shopping_user_pwd = "";
$obj_shopping_login->shopping_user_email = "";
$obj_shopping_login->remember_me = "";
function Collect_all_form_variables() {
global $obj_shopping_login;
global $error_op;
try {
$obj_shopping_login->shopping_user_email = $_POST["user_email"];
$obj_shopping_login->shopping_user_pwd = $_POST["pwd"];
if (isset($_POST['remember_me']) &&
$_POST['remember_me'] == 'yes') {
$obj_shopping_login->remember_me = 'yes';
} else {
$obj_shopping_login->remember_me = 'no';
}
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
$error_op = 'Collect_all_form_variables' . $error_op . $e->getMessage();
}
}
function check_useremail_and_password($current_user_email,$current_user_pwd) {
global $error_op;
try {
global $pdo;
$sth = $pdo->prepare("SELECT * from photostudio.user WHERE UPPER(email) = UPPER(:current_user_email) AND pwd=:current_user_pwd");
// Execute the query, replacing the placeholders with their true value
$sth->execute(array(
':current_user_email' => trim($current_user_email),
':current_user_pwd'=>current_user_pwd
));
if ($sth->rowCount() > 0) {
return true;
}
return false;
} catch (PDOException $e) {
echo 'Error: ' . $e->getMessage();
$error_op = 'check_useremail_and_password ' . $error_op . $e->getMessage();
}
return true;
}
function validate_form_stage1() {
//alert("please");
$required = array('user_email', 'pwd');
// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach ($required as $field) {
if (empty($_POST[$field])) {
$error = true;
break;
}
}
if ($error) {
return "VALIDATION_ERROR|" . $field . "|Value is Required|#END#";
} else {
return "SUCCESS";
}
}
function process_request() {
global $obj_shopping_login;
global $error_op;
$all_values_are_present = validate_form_stage1();
if (substr($all_values_are_present, 0, 16) === "VALIDATION_ERROR") {
echo $all_values_are_present;
return false;
}
Collect_all_form_variables();
if (check_useremail_and_password() == true) {
echo "Success" . $error_op;
} else {
echo "Failed" . $error_op;
}
}
?>
解决方案
Add var $ = jQuery
top of your script like..
<script type='text/javascript'>
var $ = jQuery;
// your functions here...
</script>
or
$(document).ready(function() {
// your functions here...
});
Recommend :
Add your script before closing <body>
tag like...
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Your Website</title>
</head>
<body>
<header>
</header>
<section>
</section>
<aside>
</aside>
<footer>
</footer>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('your_local_here/jquery.js"><\/script>')</script>
<script src="custom.js"></script>
<script>
// or here
</script>
</body>
</html>
这篇关于ajax发布在firebug中显示为红色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文