小编T0w*_*tuM的帖子

jquery .ajax总是返回错误 - 数据被添加到数据库

我正在尝试使用jquery ajax调用将用户添加到数据库.用户可以很好地添加到数据库中,但是ajax总是返回错误.我不知道如何检索特定的错误.下面是我的代码,表单,php和jquery.

这是jquery

$(document).ready(function() {

    //ajax call for all forms. 
    $('.button').click(function() {
        var form = $(this).closest('form');
        $.ajax({
            type: "POST",
            url: form.attr('data'),
            dataType: 'json',
            data: form.serialize(),
            success: function (response) {
                alert('something');
            },
            error: function() {
                alert('fail');
            }
        });
    });
  });
Run Code Online (Sandbox Code Playgroud)

这是PHP

<?php
include 'class_lib.php';

if(isset($_POST['username'])) {
    $user = new Users;
    $user->cleanInput($_POST['username'], $_POST['password']);
    if($user->insertUser()) {
        echo json_encode('true');
    } else {
        echo json_encode('false');
    }
}
Run Code Online (Sandbox Code Playgroud)

这是HTML

<div id='newUser' class='tool'>
    <h3>New User</h3>
    <form method='post' name='newUser' data='../php/newUser.php'>
        <span>Username</span><input type='text' name='username'><br>
        <span>Password</span><input type='password' name='password'>
        <input type='submit' …
Run Code Online (Sandbox Code Playgroud)

html javascript php ajax jquery

7
推荐指数
4
解决办法
3万
查看次数

用jQuery向nth-child添加类

我正在尝试将使用jquery的类添加到第n个子项,以便它将在IE中工作。它似乎不起作用,我遵循了一些没有结果的示例。我把小提琴挂了

http://jsfiddle.net/aosto/XghbU/

<div id='tasklist'>
    <ul class='header'>
        <li>
            <div class='listitem head'>Number</div>
            <div class='listitem head'>Description</div>
            <div class='listitem head'>Start Date</div>
            <div class='listitem head'>Due Date</div>
            <div class='listitem head'>Edit/View</div>
            <div class='listitem head'>Complete</div>
        </li>
    </ul>
</div

 #tasklist ul {
clear:both;
list-style:none;
margin:0;
padding:0;
}
 #tasklist ul li {
clear:both;
margin:3px;
padding:3px;
}
 .listitem {
float:left;
display:inline-block;
}
 .listitem2 {
width:400px;
}

    $( document ).ready(function() {
        $('#tasklist ul li:nth-child(2)').addClass("listitem2");
    });


 <head>
    <link href='css/style.php' type='text/css' rel='stylesheet'>
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="css/ie_style.css" />
<![endif]-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
    $( …
Run Code Online (Sandbox Code Playgroud)

html css jquery css-selectors

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

html ×2

jquery ×2

ajax ×1

css ×1

css-selectors ×1

javascript ×1

php ×1