{"id":714,"date":"2024-12-04T02:20:11","date_gmt":"2024-12-03T18:20:11","guid":{"rendered":"http:\/\/www.chan.ink\/?p=714"},"modified":"2024-12-04T02:20:14","modified_gmt":"2024-12-03T18:20:14","slug":"ajax%e5%90%91%e5%90%8e%e5%8f%b0%e5%8f%91%e9%80%81%e6%b6%88%e6%81%af","status":"publish","type":"post","link":"http:\/\/www.chan.ink\/index.php\/2024\/12\/04\/ajax%e5%90%91%e5%90%8e%e5%8f%b0%e5%8f%91%e9%80%81%e6%b6%88%e6%81%af\/","title":{"rendered":"ajax\u5411\u540e\u53f0\u53d1\u9001\u6d88\u606f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u7b80\u5355\u7684\u6570\u636e\u53ef\u4ee5\u5982\u4e0b\u9762\u8fd9\u6837\u83b7\u53d6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u524d\u7aef\uff1a\n    $.ajax({\n        ...\n        data:{name:11,age:122,xx:&#91;11,22,33]}\n    })\n\t$.post(url,data,callback)\nDjango\u540e\u53f0\uff1a\n\trequest.POST \n\trequest.POST.get('name')\n\trequest.POST.get('age')\n\trequest.POST.getlist('xx')<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f83\u590d\u6742\u7684\u6570\u636e\uff0c\u53ea\u80fd\u5982\u4e0b\u83b7\u53d6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u524d\u7aef\uff1a\n    $.ajax({\n        ...\n        data:JSON.stringfy({name:{k1:1,k2:666},xx:&#91;11,22,&#91;11,22,33] ]})\n    })\n\t$.post(url,JSON.stringfy({name:{k1:1,k2:666},xx:&#91;11,22,&#91;11,22,33] ]}),callback)\nDjango\u540e\u53f0\uff1a\n\trequst.body\n\tinfo = json.loads(requst.body.decode('utf-8'))\n\tinfo&#91;\"name\"]\n\tinfo&#91;\"xxx\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4e2d\uff0cJSON.stringfy({name:{k1:1,k2:666},xx:[11,22,[11,22,33] ]})\uff0c\u662f\u5c06\u8fd9\u4e9b\u6570\u636e\u5e8f\u5217\u5316\u4e3aJSON\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u53d1\u9001\u5230Django\u7684\u540e\u53f0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JSON.stringify() \u662f\u4e00\u4e2a JavaScript \u7684\u5185\u7f6e\u65b9\u6cd5\uff0c\u7528\u4e8e\u5c06 JavaScript \u5bf9\u8c61\uff08\u5305\u62ec\u6570\u7ec4\u3001\u5bf9\u8c61\u7b49\uff09\u8f6c\u6362\u4e3a JSON \u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728Django\u4e2d\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">requst.body\u62ff\u5230\u7684\u5c31\u662f\u524d\u7aef\u5e8f\u5217\u5316\u540e\u7684\u5b57\u7b26\u4e32\uff0c\u662f\u4e00\u4e2a\u5b57\u8282<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">requst.body.decode(&#8216;utf-8&#8217;)\uff0c\u4ee5utf-8\u7684\u7f16\u7801\u65b9\u5f0f\uff0c\u5c06\u5b57\u8282\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">json.loads(requst.body.decode(&#8216;utf-8&#8217;))\uff0c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><app-translate-content _nghost-ng-c341168634=\"\" class=\"eusoft-translate-container-span-en ng-star-inserted\"><span _ngcontent-ng-c341168634=\"\" class=\"eusoft-eudic-chrome-extension-translate-content\"><span _ngcontent-ng-c341168634=\"\" class=\"eusoft-eudic-chrome-extension-translate-white-space ng-star-inserted\">\u00a0<\/span>\u5c06 JSON \u5b57\u7b26\u4e32\u89e3\u6790\u6210 Python \u5bf9\u8c61\u3002json.loads() \u51fd\u6570\u4f1a\u5c06 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a Python \u5b57\u5178\u6216\u5217\u8868\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e JSON \u7684\u7ed3\u6784\u3002<span _ngcontent-ng-c341168634=\"\" class=\"eusoft-eudic-translate-loading-tag ng-star-inserted\" data-eusoft-eudic-loading-template-original-text=\"\u5728Django\u4e2d\"><\/span><\/span><\/app-translate-content><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u5355\u7684\u6570\u636e\u53ef\u4ee5\u5982\u4e0b\u9762\u8fd9\u6837\u83b7\u53d6 \u8f83\u590d\u6742\u7684\u6570\u636e\uff0c\u53ea\u80fd\u5982\u4e0b\u83b7\u53d6 \u5176\u4e2d\uff0cJSON.stringfy({name:{k1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-714","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/comments?post=714"}],"version-history":[{"count":1,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/714\/revisions"}],"predecessor-version":[{"id":715,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/714\/revisions\/715"}],"wp:attachment":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/media?parent=714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/categories?post=714"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/tags?post=714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}