第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

無(wú)法從ajax獲取數(shù)據(jù)到php頁(yè)面

無(wú)法從ajax獲取數(shù)據(jù)到php頁(yè)面

PHP
慕田峪4524236 2021-09-18 17:05:53
我設(shè)計(jì)了一個(gè)簡(jiǎn)單的頁(yè)面,用戶可以使用 html 輸入名稱、密碼和圖像。我嘗試使用 ajax 將這些數(shù)據(jù)發(fā)送到特定的 php 頁(yè)面,但我無(wú)法實(shí)現(xiàn)這一點(diǎn)。我是怎么做這件事的html代碼<?php include('connection.php'); ?>             <form id="form" enctype="multipart/form-data">        <table>            <tr>                <td>Name:</td>                <td><input type="name" id="name"></td>            </tr>            <tr>                <td>Password:</td>                <td><input type="password" id="pass"></td>            </tr>            <tr>                <td>Photos:</td>                <td><input type="file" id="photos"></td>            </tr>            <tr>                <td><input type="submit" id="go"></td>            </tr>        </table>    </form>jQuery 和 ajax<script>    $(document).ready(function(){        $('#go').click(function(){                  var img_name = $('#img_name').val();            var name = $('#name').val();            var pass = $('#pass').val();              $.ajax({                   type : "POST",                url : "singup_submit.php",                data : { img_name:img_name, name:name, pass:pass},                success : function(done){                    alert(done);                }                });            });    });</script>php代碼<?php    include('connection.php');        if(isset($_POST)){           $name = $_POST['name'];        $pass = $_POST['pass'];        $img_name=$_FILES['img_name']['name'];        $qr="INSERT INTO data (name,pass,img_name) VALUES ('$name','$pass','$img_name')";        $ex=mysqli_query($con,$qr) or die(mysqli_error($con));            if($ex==1)            echo 'done';        else                        echo 'not done';}
查看完整描述

2 回答

?
慕尼黑的夜晚無(wú)繁華

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊

按照此代碼..它可能會(huì)幫助你


<script>

    $(document).ready(function(){

        $("#go").click(function(){

            var name    = $("#name").val();

            var pasword = $("#password").val();

            var photos  = $("#photos").val();

            if(name==''||pass==''||photos==''){

              alert("Please Fill All Fields");

            }

            else{

              $.ajax({

                type   : "POST",

                url    : "singup_submit.php",

                data   : formData,

                cache  : false,

                success: function(result){

                alert(result);

                }

              });

            }

            return false;

        });

      });

  </script>


查看完整回答
反對(duì) 回復(fù) 2021-09-18
?
慕姐8265434

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊

您沒(méi)有在 ajax 請(qǐng)求中發(fā)送任何文件。


$(document).ready(function(){

$("#go").on('submit',function(e){

   e.preventDefault()


    $.ajax({

        url: 'singup_submit.php',

        type: 'POST',

        data: new FormData(this),

        contentType: false,

        processData: false,

        success: function(response){

                alert(done);

            },

            error: function(data){

                console.log("error");

                console.log(data);

            }

          },

       });

    });

  });

然后像你現(xiàn)在所做的那樣從 php 中的全局變量中獲取數(shù)據(jù)。并請(qǐng)像這樣為您的表單字段指定名稱


 <form id="form" enctype="multipart/form-data">

    <table>

        <tr>

            <td>Name:</td>

            <td><input type="name" name="name" id="name"></td>

        </tr>

        <tr>

            <td>Password:</td>

            <td><input type="password" name="password" id="pass"></td>

        </tr>

        <tr>

            <td>Photos:</td>

            <td><input type="file" name="img" id="photos"></td>

        </tr>

        <tr>

            <td><input type="submit" name="submit" id="go"></td>

        </tr>

    </table>

</form>

它應(yīng)該工作。


查看完整回答
反對(duì) 回復(fù) 2021-09-18
  • 2 回答
  • 0 關(guān)注
  • 137 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)