惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - 问天何必

网文小说应该怎么从零开始设计故事情节呢? 拒绝花里胡哨,这次来真的,又做了一个导航+超级搜索, 50+功能自定义调整。 一个优秀的导航站。 1个能顶100个 Redis 挂了自动重启的shell 脚本。 宝塔linux面板, 服务器日志分析与流量统计这款插件的mysql版优化。 苹果cms自动采集,重复执行遇到“上次执行时间: --跳过”的解决办法 苹果cms, 后台设置保存不了的解决办法 c# 【电影搜索引擎】采集电影站源码 解决 C:\WINDOWS\system32\inetsrv\rewrite.dll 未能加载。返回的数据为错误. - 问天何必 安利一个聚合搜索导航站,及怎么样设置成默认的搜索引擎 img error 图片加载失败的最佳方案 百度站长平台HTTPS认证所遇到的坑 百度Sitemap生成器 女朋友经常问影视剧, 答不上来怎么办? fiddler抓取手机上https数据配置和失败的解决办法 STSDB 一 windows2012 IIS部署GeoTrust证书踩过的坑。 百度编辑器解决span被过滤, 自动加P标签 代码记录:使用Aforge.net让视频图像反转180度
jquery ajax GET POST 跨域请求实现
问天何必 · 2015-07-01 · via 博客园 - 问天何必

 同一段逻辑代码需要在多个网站中使用, 每个网站都新建一个ashx真是扯蛋的作法,  所以想只请求一处的ashx, 这样便于维护和修改, 那么,ajax跨域问题就来了。 

废话少说, 直接上代码,  我现在做的是GET请求的。 POST请求同理。 

首先整改ashx,加入支持跨域请求的代码。

        context.Response.ContentType = "text/plain"; 
        string active = context.Request.QueryString["active"];
        
        string rs = "0";
        if (active == "3")
        {
            string oid = TGM.BaseOpera.String.replacesql(context.Request.QueryString["oid"]);
            if (!string.IsNullOrEmpty(oid))
            {
                tansar.BLL.order tbo = new tansar.BLL.order();
                string flag = tbo.GetSID(oid);
                if (flag != "1000")
                    rs = "ok";
            }
        }
        #region 支持跨域请求
        context.Response.ClearHeaders();
        string origin = context.Request.Headers["Origin"];
        context.Response.AppendHeader("Access-Control-Allow-Origin",string.IsNullOrEmpty(origin) ? "*" : origin);
        string requestHeaders = context.Request.Headers["Access-Control-Request-Headers"];
        context.Response.AppendHeader("Access-Control-Allow-Headers",string.IsNullOrEmpty(requestHeaders) ? "*" : requestHeaders);
        context.Response.AppendHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
        #endregion 
        
        context.Response.Write(rs);

然后ajax中的js方法:

function getFlag(d) {
                $.ajax({
                    type: "get",
                    async: false,
                    url: "http://www.8kmm.com",
            data: d,
dataType: "text",
            success:
function (data) {
              if (data == "ok") {
               location.href
= "/user/orderdetail.aspx?oid=<%=Onumber %>"; }
              },
            error:
function (XMLHttpRequest, textStatus, errorThrown) {
               alert("请求数据异常:" + errorThrown);
              }
      });

}

做前端开发, 浏览器的开发者工具能帮大忙, 比如webkit内核的, ff的。