{"id":3236,"date":"2014-11-11T09:01:29","date_gmt":"2014-11-11T01:01:29","guid":{"rendered":"https:\/\/sdeno.com\/?p=3236"},"modified":"2014-11-11T09:01:29","modified_gmt":"2014-11-11T01:01:29","slug":"%e6%8c%89%e9%92%ae%e7%9a%84ajax%e8%af%b7%e6%b1%82%e6%97%b6%ef%bc%8c%e4%b8%80%e6%ac%a1%e7%82%b9%e5%87%bb%e4%b8%a4%e6%ac%a1%e6%8f%90%e4%ba%a4%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=3236","title":{"rendered":"\u6309\u94ae\u7684ajax\u8bf7\u6c42\u65f6\uff0c\u4e00\u6b21\u70b9\u51fb\u4e24\u6b21\u63d0\u4ea4\u7684\u95ee\u9898"},"content":{"rendered":"<p>\u9875\u9762\u4e2d\u7684\u6309\u94ae\u7684type\u662fsubmit\u7684\uff1a &lt;input type=&#8221;submit&#8221; value=&#8221;Create&#8221; id=&#8221;submit&#8221; \/&gt;<\/p>\n<p>ajax\u7684\u8bf7\u6c42\uff0c\u5728JQuery\u4e2d\u662f\uff1a<\/p>\n<p><span style=\"color: #000000;\">$(<\/span><span style=\"color: #0000ff;\">function<\/span><span style=\"color: #000000;\">\u00a0()\u00a0{<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$(&#8216;#submit&#8217;).click(<\/span><span style=\"color: #0000ff;\">function<\/span><span style=\"color: #000000;\">\u00a0()\u00a0{<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000ff;\">var<\/span><span style=\"color: #000000;\">\u00a0createGenreForm\u00a0=\u00a0$(&#8216;#createGenreForm&#8217;);<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000ff;\">if<\/span><span style=\"color: #000000;\">\u00a0(createGenreForm.valid())\u00a0{<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000ff;\">var<\/span><span style=\"color: #000000;\">\u00a0obj\u00a0=\u00a0{<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Name:\u00a0$(&#8216;#Name&#8217;).val(),<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Description:\u00a0$(&#8216;#Description&#8217;).val()<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0};<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000ff;\">var<\/span><span style=\"color: #000000;\">\u00a0jsonSerialized\u00a0=\u00a0JSON.stringify(obj);<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$.ajax({<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0type:\u00a0&#8220;POST&#8221;,<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0url:\u00a0createGenreForm.attr(&#8216;action&#8217;),<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0dataType:\u00a0&#8220;json&#8221;,<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0contentType:\u00a0&#8220;application\/json;\u00a0charset=utf-8&#8221;,<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0data:\u00a0jsonSerialized,<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0success:\u00a0<\/span><span style=\"color: #0000ff;\">function<\/span><span style=\"color: #000000;\">\u00a0(result)\u00a0{<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0alert(result.Message);<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0error:\u00a0<\/span><span style=\"color: #0000ff;\">function<\/span><span style=\"color: #000000;\">\u00a0(error)\u00a0{<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0alert(&#8220;There\u00a0was\u00a0an\u00a0error\u00a0posting\u00a0the\u00a0data\u00a0to\u00a0the\u00a0server:\u00a0&#8221;\u00a0+\u00a0error.responseText);<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/span><br style=\"color: #000000;\" \/><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0\u00a0\u00a0\u00a0});<\/span><\/p>\n<p>\u53d1\u751f\u4e24\u6b21\u63d0\u4ea4\u7684\u539f\u56e0\u662f\u5728\u6267\u884c\u5b8cajax\u8bf7\u6c42\u540e\uff0c\u5e76\u6ca1\u6709\u963b\u6b62submit\u7684\u884c\u4e3a\uff0c\u6240\u4ee5\u89e3\u51b3\u65b9\u6cd5\u6709\u4e24\u79cd\uff1a<\/p>\n<p>1\u3001\u4e0d\u4f7f\u7528type\u4e3asubmit\u7c7b\u578b\u7684\u6309\u94ae\uff0c\u800c\u662f\u4f7f\u7528type\u662fbutton\u7684\u6309\u94ae\u3002<\/p>\n<p>2\u3001\u5728$(&#8216;#submit&#8217;).click\u51fd\u6570\u4e2d\uff0c\u6700\u540e\u52a0\u4e00\u884creturn false;\uff0c\u5373\u53ef\u963b\u6b62submit\u3002<\/p>\n<p>\u4e00\u70b9\u8bf4\u660e\uff1a\u4e3a\u4ec0\u4e48\u5728\u6807\u9898\u4e2d\u8981\u5d4c\u5165\u82f1\u6587\uff1f\u539f\u56e0\u662f\u4e3a\u4e86\u80fd\u591f\u8ba9\u56fd\u5916\u7684\u7f51\u53cb\u80fd\u67e5\u8be2\u5230\u8fd9\u7bc7\u6587\u7ae0\u3002\u5e73\u5e38\u5728Google\u4e0a\u67e5\u8d44\u6599\u7684\u65f6\u5019\uff0c\u7ecf\u5e38\u53c2\u8003\u56fd\u5916\u7f51\u53cb\u7684\u535a\u5ba2\uff0c\u5e2e\u52a9\u6211\u89e3\u51b3\u4e86\u5f88\u591a\u95ee\u9898\uff0c\u6240\u4ee5\u6211\u4e5f\u60f3\u8ba9\u4ed6\u4eec\u80fd\u591f\u53c2\u8003\u6211\u5199\u7684\u5185\u5bb9\u3002\u5f53\u7136\u6587\u4e2d\u6211\u4e0d\u53ef\u80fd\u5168\u90e8\u8bd1\u4e3a\u82f1\u6587\uff0c\u6240\u4ee5\u6211\u5c3d\u91cf\u628a\u4ee3\u7801\u7c98\u5168\uff0c\u9760\u4ee3\u7801\u8bf4\u8bdd\u5427\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9875\u9762\u4e2d\u7684\u6309\u94ae\u7684type\u662fsubmit\u7684\uff1a &lt;input type=&#8221;submit&#038;#8221 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,13],"tags":[],"class_list":["post-3236","post","type-post","status-publish","format-standard","hentry","category-11","category-jquery"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/3236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3236"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/3236\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}