我的ajax代码有问题,我不知道该怎么办

时间:2018-09-24 02:35:26

标签: jquery html ajax

那是代码。问题是,当我按下按钮时它什么也没做,我只想检查ajax是否有效。我的意思是,当我按下按钮来提醒我数据时。 这是index.php

<html>
<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <div class = "container">
        <div class = "jumbotron">
            <input type = "username" name = "username" id = "username" placeholder = "username">
            <input type = "password" name = "password" id = "password" placeholder = "password">
            <button name = "startRegister" id = "startRegister">Register</button>
        </div>
    </div>
</body>
<script>
    $(document).ready(function(){
        $('#startRegister').click(function(event){
            event.preventDefault();
            var user = $('#username').val();
            var pass = $('#password').val();
            $.ajax({
                url:"register.php",
                method: "post",
                data: {username: user, password: pass},
                succes:function(data){
                 alert(data);
                }
            });
        });
    });
</script>
</html>

这是register.php

<?php
 echo "Welcome to first php !";
?>

我的文件中的图像: enter image description here

1 个答案:

答案 0 :(得分:-1)

如果它对您没有任何帮助,那么您可能没有达到目标的“ 成功”触发器。最好打开控制台(如果您使用的是Google Chrome浏览器,请右键单击-> library(shiny) ui = fluidPage( titlePanel("Plot or Example?"), sidebarLayout( sidebarPanel( checkboxGroupInput("my_choices", "Example or Plot",choices = c("Plot", "Example"), selected = "Plot"),width=2), mainPanel( conditionalPanel( condition = "input.my_choices == 'Plot'", plotOutput("my_test1") ), conditionalPanel( condition = "input.my_choices == 'Example'", uiOutput("my_test2") ), conditionalPanel( condition = "input.my_choices.includes('Example') && input.my_choices.includes('Plot')", plotOutput("my_test1a"), uiOutput("my_test2a") ) ) ) ) server = function(input, output) { output$my_test1 <- output$my_test1a <- renderPlot({plot(runif(100))}) output$my_test2 <- output$my_test2a <- renderUI({ images <- c("http://www.i2symbol.com/images/abc-123/o/white_smiling_face_u263A_icon_256x256.png") tags$img(src= images) }) } shinyApp(ui, server) ),然后单击按钮后检查其中是否有任何消息。

在您复制的代码中,您拥有“成功”,而触发器实际上是“成功”(双精度s)

此外,您可以扩展AJAX调用以进行错误处理:

Inspect