ajax添加資料

來源:互聯網
上載者:User

標籤:cli   失敗   rip   文檔   ges   bsp   asc   img   htm   

一、用到資料庫中的minzu表:

添加頁面代碼如下:

<title>無標題文檔</title><script src="jquery-3.2.0.min.js"></script></head><body><h1>添加資料</h1><div>代號:<input type="text" id="code" /></div><div>名稱:<input type="text" id="name1" /></div><input type="button" value="添加" id="add" /></body><script type="text/javascript">$("#add").click(function(){    var code = $("#code").val();    var name1 = $("#name1").val();        $.ajax({        url:"tianjia.php", //要處理的頁面        data:{c:code,n:name1},  //要傳過去的資料        type:"POST",  //提交方式        dataType:"TEXT", //返回的資料類型,TEXT字串 JSON返回JSON XML返回XML;dataType中T要大寫!!        success: function(data){ //回呼函數,data為形參,是從login-cl.php頁面返回的值            if(data.trim()=="OK") //trim()去空格            alert("添加成功");            else            alert("添加失敗");        }            });})</script></html>

處理頁面:

<?php$code = $_POST["c"];$name1 = $_POST["n"];require "DBDA.class.php";$db = new DBDA();$sql = "insert into minzu values(‘{$code}‘,‘{$name1}‘)";if($db->query($sql,0)){    echo "OK";}else{    echo "NO";}

最終效果:

 

ajax添加資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.