关于ajax

    xiaoxiao2021-03-25  90

    一、使用ajax提交个别数据

    $.ajax({ url : "searchajax", type : "GET", data : {keyWord : "沈",teacherPfId:"xxxxxxxx"}, contentType : "application/x-www-form-urlencoded; charset=utf-8", success : function(data) { alert("成功了。。。。") }, error: function (msg) { alert("出錯了:"+msg); } });

    一定注意:使用该形式时,一定要先引入jquery的js文件

    <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

    二、使用ajax提交form表单

    html代码

    <form id="tf"> <input type="file" name="img"/> //提交文件 <input type="text" name="username"/> <input type="button" value="提" onclick="test();"/> ............. </form>

    js代码

    function test(){ var form = new FormData(document.getElementById("tf")); $.ajax({ url:"/public/testupload/XXX", type:"post", data:form, processData:false, contentType:false, success:function(data){ console.log("成功"); location.reload(true); //刷新当前页面 }, error:function(e){ alert("错误!!"); } }); get();//此处为上传文件的进度条 }
    转载请注明原文地址: https://ju.6miu.com/read-14247.html

    最新回复(0)