jquery ajax 同步异步提交

前置知识:ajax原理,json字符串进行信息传递。

  • Ajax主要的功能是实现了浏览器端 异步 访问服务器:通过浏览器的XMLHttpRequest对象发出小部分数据,与服务端进行交互,

服务端返回小部分数据,然后更新客户端的部分页面。

  • json是Ajax发送小部分数据的一种轻量级数据格式,可以简单易懂的给服务器或者浏览器交互数据,包括json对象,json数组对象。

jquery 库中已经封装了ajax请求的方法。

jquery.ajax([settings])。发请求并且能得知成功还是失败。

  • type:类型,”POST”或者”GET”,默认是”GET”。
  • url:发送请求的地址。
  • data:是一个对象,连同请求发送到服务器的数据
  • dataType:预期服务器返回的数据类型。如果不指定,jQuery将自动根据HTTP包含的MIME信息来智能判断,一般我们采用json个数,可以设置为”json”。
  • success:是一个方法,请求成功后的回调函数。传入返回后的数据,以及包含成功代码的字符串。
  • error:是一个方法、请求失败时调用此函数。传入XMLHttpRequest对象。
$.ajax({
                cache: true,
                type: "POST",
                url:ajaxCallUrl,
                dataType : "json",//这里的dataType就是返回回来的数据格式了html,xml,json
                data{
                    name:$("#staffName").val(),
                    number:$("#staffNumber").val(),
                    sex:$("#staffSex").val(),
                    job:$("#staffJob").val(),
                },
                async: false,
                error: function(request) {
                    alert("Connection error");
                },
                success: function(data) {
                    $("#commonLayout_appcreshi").parent().html(data);
                }
        });

整个表单提交

 $.ajax({
                cache: true,
                type: "POST",
                url:ajaxCallUrl,
                data:$('#yourformid').serialize(),// 你的formid
                async: false,
                error: function(request) {
                    alert("Connection error");
                },
                success: function(data) {
                    $("#commonLayout_appcreshi").parent().html(data);
                }
        });
© 版权声明
THE END
喜欢就支持以下吧
点赞0
分享
评论 共30条
  • wangjianjilei

    昵称

  • 取消
    昵称
    • wangjianjilei
    • porno0
      By interspersing photographs, diagrams and other graphics into your blog, you are actually perfecting the overall image of the page. Marjorie Micah Hoopes
      6月前回复
    • wangjianjilei
    • indir0
      I got what you mean,bookmarked, very decent web site. Ruthie Gallagher Reagen
      4月前回复
    • wangjianjilei
    • torrent0
      Glad to be one of many visitors on this awful website :D. Brittani Shayne Catha
      4月前回复
    • wangjianjilei
    • watch0
      I am not real good with English but I come up this real leisurely to understand. Rosamund Payton Arlyne
      4月前回复
    • wangjianjilei
    • movie online0
      Hingga saat ini saya belum bisa membantah keinginan klien terkait itu oleh karena selama teknik backlink masih work dan belom berdampak pada kebanyakan klien yg saya pegang. Karena masih minimnya track record /bahan yg bisa meyakinkan klien untuk melakukan perubahan SEO disisi lain selain backlink. Rosana Broderick Rochella
      4月前回复
    • wangjianjilei
    • movie online0
      Remarkable! Its genuinely awesome paragraph, I have got much clear idea about from this paragraph. Monika Winston Ermeena Bren Darryl Puff
      3月前回复
    • wangjianjilei
    • series online0
      Pretty! This was a really wonderful post. Thanks for supplying these detail Della Marwin Fabrianna
      3月前回复
    • wangjianjilei
    • online0
      This is definitely good tidings my friend. you are a remarkably good scribbler . i want to portion with you my website as well. command me what do you deem about it Dina Ian Gerbold
      3月前回复
    • wangjianjilei
    • torrent0
      A round of applause for your blog. Really thank you! Fantastic. Oralla Shurlock Purington
      3月前回复
    • wangjianjilei
    • lost0
      Ridiculous quest there. What occurred after? Take care! Shoshana Torey Pudendas
      3月前回复
    • wangjianjilei
    • watch0
      Everything is very open with a very clear clarification of the issues. It was really informative. Your site is very helpful. Thanks for sharing! Eimile Ingram Leann
      3月前回复
    • wangjianjilei
    • dizi0
      141789 121842What a excellent viewpoint, nonetheless is just not produce every sence by any means discussing this mather. Just about any technique thanks and also i had try and discuss your post directly into delicius but it surely appears to be an issue in your blogging is it possible you should recheck this. thank you just as before. 269951 Floris Duane Ogdon
      3月前回复
    • wangjianjilei
    • bedava0
      I conceive you have noted some very interesting points , thankyou for the post. Mignon Enrico Strohbehn
      3月前回复
    • wangjianjilei
    • bluray0
      A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. Alvera Ximenes Jacquie
      3月前回复
    • wangjianjilei
    • dizi0
      I conceive you have mentioned some very interesting details , thanks for the post. Jelene Benedick Berfield
      3月前回复
    • wangjianjilei
    • bluray0
      I think the admin of this web page is truly working hard in favor of his web page, as here every stuff is quality based stuff. Berri Garreth Falda
      3月前回复
    • wangjianjilei
    • torrent0
      As I website possessor I think the subject matter here is really great, regards for your efforts. Carmita Tom Nordine
      3月前回复
    • wangjianjilei
    • erotik0
      What a great job BuildWall does! Except their excellent services they take active social position and help children! I appreciate such lifestyle and attitide to work. I hope they will organize more and more charity events and support our youth. Rebecca Damon Ot
      3月前回复
    • wangjianjilei
    • indirmeden0
      I simply hope to share it with you that I am new to having a blog and undeniably liked your page. Very likely I am inclined to bookmark your blog post . You seriously have stunning article materials. Like it for share-out with us all of your internet site webpage Ulrica Jammal Spatola
      3月前回复
    • wangjianjilei
    • indirmeden0
      A fascinating discussion is worth comment. I do think that you should publish more about this topic, it may not be a taboo matter but generally people do not discuss such topics. To the next! Many thanks!! Charleen Delmar Kary
      3月前回复
    • wangjianjilei
    • erotik0
      Asking questions are genuinely nice thing if you are not understanding something completely, however this paragraph provides fastidious understanding even. Emma Kilian Jenine
      3月前回复
    • wangjianjilei
    • erotik0
      Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a little bit, but instead of that, this is fantastic blog. A fantastic read. I will certainly be back.| Adrianne Ivor Holton
      3月前回复
    • wangjianjilei
    • turkce0
      Thank you for the auspicious writeup. It in truth was once a amusement account it. Glance complex to more brought agreeable from you! By the way, how can we keep up a correspondence? Cassandry Fransisco Soelch
      3月前回复
    • wangjianjilei
    • erotik0
      As the admin of this website is working, no doubt very rapidly it will be well-known, due to its feature contents.| Loutitia Tomlin Dewayne
      3月前回复
    • wangjianjilei
    • erotik0
      You need to be a part of a contest for one of the most useful websites on the net. I most certainly will recommend this blog! Delcina Miner Lodovico
      3月前回复
    • wangjianjilei
    • erotik0
      Very good write-up. I absolutely love this website. Keep writing! Rodie Shelley Shanley
      3月前回复
    • wangjianjilei
    • turkce0
      free child porn in google in my websites bursa escort Brittney Evyn Treiber
      3月前回复
    • wangjianjilei
    • erotik0
      Excellent website. Plenty of useful information here. I am sending it to a few buddies ans additionally sharing in delicious. And certainly, thanks in your effort! Catha George Raquel
      3月前回复
    • wangjianjilei
    • erotik0
      I visited multiple web pages however the audio feature for audio songs present at this website is genuinely excellent.| Devan Hamel Gerhan
      3月前回复
    • wangjianjilei
    • turkce0
      I am regular reader, how are you everybody? This article posted at this web site is in faxt nice. Lissy Lorant Ries
      3月前回复