{"id":241,"date":"2020-10-01T10:09:35","date_gmt":"2020-10-01T02:09:35","guid":{"rendered":"https:\/\/blog.xbgit.cn\/?p=241"},"modified":"2020-10-01T10:09:35","modified_gmt":"2020-10-01T02:09:35","slug":"jquery%e8%bf%9b%e8%a1%8cajax%e8%ae%bf%e9%97%ae%e6%97%b6%e6%97%a0%e6%b3%95%e8%8e%b7%e5%be%97%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/blog.xbgit.cn\/index.php\/2020\/10\/01\/jquery%e8%bf%9b%e8%a1%8cajax%e8%ae%bf%e9%97%ae%e6%97%b6%e6%97%a0%e6%b3%95%e8%8e%b7%e5%be%97%e6%95%b0%e6%8d%ae\/","title":{"rendered":"jQuery\u8fdb\u884cajax\u8bbf\u95ee\u65f6\u65e0\u6cd5\u83b7\u5f97\u6570\u636e"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u62a5\u9519\u4fe1\u606f:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"basic\" class=\"language-basic\">jquery.js:18 Access to XMLHttpRequest at 'https:\/\/api.xbgit.cn\/***' from origin 'https:\/\/localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.\nsend @ jquery.js:18\najax @ jquery.js:18<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"134\" src=\"https:\/\/blog.xbgit.cn\/wp-content\/uploads\/2020\/10\/Snipaste_2020-10-01_09-59-03-1024x134.png\" alt=\"\" class=\"wp-image-244\" srcset=\"https:\/\/blog.xbgit.cn\/wp-content\/uploads\/2020\/10\/Snipaste_2020-10-01_09-59-03-1024x134.png 1024w, https:\/\/blog.xbgit.cn\/wp-content\/uploads\/2020\/10\/Snipaste_2020-10-01_09-59-03-300x39.png 300w, https:\/\/blog.xbgit.cn\/wp-content\/uploads\/2020\/10\/Snipaste_2020-10-01_09-59-03-768x101.png 768w, https:\/\/blog.xbgit.cn\/wp-content\/uploads\/2020\/10\/Snipaste_2020-10-01_09-59-03-1536x201.png 1536w, https:\/\/blog.xbgit.cn\/wp-content\/uploads\/2020\/10\/Snipaste_2020-10-01_09-59-03-1568x205.png 1568w, https:\/\/blog.xbgit.cn\/wp-content\/uploads\/2020\/10\/Snipaste_2020-10-01_09-59-03.png 1642w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u51b3\u529e\u6cd5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java\">package cn.xbgit.config;\n\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.web.servlet.config.annotation.CorsRegistry;\nimport org.springframework.web.servlet.config.annotation.EnableWebMvc;\nimport org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;\n\n\/**\n * Simple to Introduction\n *\n * @ProjectName: 9-29-test\n * @Package: cn.xbgit.config.CorsConfig\n * @ClassName: CorsConfig\n * @Description: [\u4e00\u53e5\u8bdd\u63cf\u8ff0\u8be5\u7c7b\u7684\u529f\u80fd]\n * @Author: sky\n * @CreateDate: 2020\/10\/1 9:44\n * @UpdateUser: sky\n * @UpdateDate: 2020\/10\/1 9:44\n * @UpdateRemark: [\u8bf4\u660e\u672c\u6b21\u4fee\u6539\u5185\u5bb9]\n * @Version: [v1.0]\n *\/\n@Configuration\n@EnableWebMvc\npublic class CorsConfig extends WebMvcConfigurerAdapter {\n    @Override\n    public void addCorsMappings(CorsRegistry registry) {\n        registry.addMapping(\"\/**\") \/\/\u8868\u793a\u672c\u5e94\u7528\u7684\u6240\u6709\u65b9\u6cd5\u90fd\u4f1a\u53bb\u5904\u7406\u8de8\u57df\u8bf7\u6c42\n\/\/                .allowedOrigins(\"http:\/\/localhost:8081\")\n\/\/                .allowedMethods(\"*\") \/\/\u8868\u793a\u5141\u8bb8\u901a\u8fc7\u7684\u8bf7\u6c42\u6570\n\/\/                .allowedHeaders(\"*\") \/\/\u8868\u793a\u5141\u8bb8\u7684\u8bf7\u6c42\u5934\n                ;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ecf\u8fc7\u8fd9\u6837\u7684\u914d\u7f6e\u4e4b\u540e\uff0cajax\u53ef\u4ee5\u8de8\u57df\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u9605\u76f8\u5173\u8d44\u6599\u540e\u7684\u77e5\u6b64\u64cd\u4f5c\u4f1a\u5bfc\u81f4\u5b89\u5168\u6027\u964d\u4f4e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u62a5\u9519\u4fe1\u606f: \u89e3\u51b3\u529e\u6cd5: \u7ecf\u8fc7\u8fd9\u6837&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3,19,6],"tags":[],"class_list":["post-241","post","type-post","status-publish","format-standard","hentry","category-2","category-3","category--java","category-6"],"_links":{"self":[{"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/posts\/241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/comments?post=241"}],"version-history":[{"count":0,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/posts\/241\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/media?parent=241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/categories?post=241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/tags?post=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}