前端 ajax get请求

 $.ajax({
url: "API地址",
type: 'get',
dataType: 'jsonp',
async: true,
processData: true,
contentType: false, success: function (res) {
console.log(res)
},
error: function (Error) {
console.log(Error)
}
})

前端 ajax post请求

$.ajax({
type: 'post',
url: 'API地址',
data: data,
dataType: "json",
crossDomain: true,
success: function (data) {
console.log(data); },
error: function (data) {
console.log(data); }
});

c# 后端 get请求

var res="最好转换成json";
string callback = this.Request["callback"];
return Content(callback + "(" + res + ")");

c# 后端 post 请求

//1.可以创建一个FilterAttribute
public class PostAPIController : ActionFilterAttribute
{
     //override OnActionExecuting
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//设置
filterContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
filterContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Methods", "POST");
filterContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Headers", "x-requested-with,content-type"); base.OnActionExecuting(filterContext);
}
}
    //2.post请求代码块   加上过滤器 PostAPIController
    
[HttpPost]
[PostAPIController]
public ActionResult AddReadNum(int newid)
{
try
{
*******
          *******
if (string.IsNullOrEmpty(callback))
{
return Json(result, JsonRequestBehavior.AllowGet);
}
else
{
string res = JsonToots.ModelToJson(result);
return Content(callback + "(" + res + ")"); } }
catch (Exception ex)
{
******
}
}

c# 跨域api的更多相关文章

  1. 跨域API

    跨域API 简单跨域请求 只需要简单的设置允许跨域就可以了 def set_default_headers(self): self.set_header('Access-Control-Allow-O ...

  2. MVC跨域API

    API using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Ne ...

  3. php跨域请求

    跨域api服务器设置 header('content-type:application:json;charset=utf8'); header('Access-Control-Allow-Origin ...

  4. Ajax跨域问题

    为了数据安全,默认情况下ajax请求是不支持跨域访问. 但是可以通过以下方法让ajax接收跨域API地址 第一种:JSONP比较老,较简单的请求可以考虑使用. JS代码 $(function () { ...

  5. 【Vue+Node】解决axois请求数据跨域问题

    项目基于Vue前端+Node后台,启动两个服务,请求数据时,端口不一致造成跨域报错: (No 'Access-Control-Allow-Origin' header is present on th ...

  6. Vue使用vue-recoure + http-proxy-middleware + vuex配合promise实现基本的跨域请求封装

    使用vue init webpack 你的项目名称初始化一个vue的项目 安装依赖 npm install vue-resource http-proxy-middleware vuex koa 在项 ...

  7. 原创:【ajax | axios跨域简单请求+复杂请求】自定义header头Token请求Laravel5后台【亲测可用】

    如标题:我想在ajax的header头增加自定义Token进行跨域api认证并调用,api使用laravel5编写,如何实现? 首先,了解下CORS简单请求和复杂请求.  -- CORS简单请求 -- ...

  8. springboot+vue2.x 解决session跨域失效问题

    服务端SpringBoot2.x   :localhost:8082 前端Vue2.x                 :localhost:81 前后端的端口号不同,为跨域,导致前端访问后端时,每次 ...

  9. uni-app运行到浏览器跨域H5页面的跨域问题解决方案

    官方文档对跨域的解决方案推荐: https://ask.dcloud.net.cn/article/35267 更方便的解决方案 项目根目录直接创建一个vue.config.js文件,并在里面配置代理 ...

随机推荐

  1. Redis持久化之RDB&&AOF的区别

    在说Redis持久化之前,需要搞明白什么是数据库状态这个概念,因为持久化的就是将内存中的数据库状态保存到磁盘上.那么什么是数据库状态呢?Redis是一个key-value数据库服务器,一般默认是有16 ...

  2. ctags的如何生成tags文件

    tags 在使用vim编程和浏览代码是非常有用.可以用CTRL+]和CTRL+t 来回跳转关键字.先生成自己工作目录的tags.最简单粗暴用法: $cd yourwork $ctags -R * 这样 ...

  3. ASP.NET MVC5 高级编程-学习日记-第三章 视图

    开发人员之所以花费大量时间来重点设计控制器和模型对象,是因为在这些领域中,精心编写的整洁代码是开发一个可维护Web应用程序的基础. 3.1 视图的作用 视图的职责是向用户提供用户界面.当控制器针对被请 ...

  4. [vuejs] 终端npm run dev 不能自动打开浏览器运行项目解决办法

    终端执行: npm run dev 出现: I Your application is running here: http://localhost:8080 但并没有打开浏览器运行项目 解决办法: ...

  5. 设计模式《JAVA与模式》之解释器模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述解释器(Interpreter)模式的: 解释器模式是类的行为模式.给定一个语言之后,解释器模式可以定义出其文法的一种表示,并同时提供一个 ...

  6. 【bzoj3218】a+b Problem 最小割+主席树

    数据范围:$n≤5000$,$a,l,r≤10^9$,$b,w,p≤2\times 10^5$. 我们考虑一种暴力的最小割做法: 首先令$sum=\sum\limits_{i=1}^{n} b_i+w ...

  7. sql 数据库日志收缩

    SQL2008 的收缩日志 由于SQL2008对文件和日志管理进行了优化,所以以下语句在SQL2005中可以运行但在SQL2008中已经被取消:(SQL2005)Backup Log DNName w ...

  8. android stdio Error Could not find com.android.tools common 25.2.2

    Error:Could not find com.android.tools:common:25.2.2. Searched in the following locations: file:/D:/ ...

  9. tensorflow学习总结之reduce_sum函数

    tensorflow里面集成了许多基于统计的数学函数,类似于reduce_sum,reduce_mean,reduce_min,reduce_max,等,根据字面意思分别是求和,求平均,求最大,求最小 ...

  10. python多线程-Semaphore(信号对象)

    Semaphore(value=1) Semaphore对象内部管理一个计数器,该计数器由每个acquire()调用递减,并由每个release()调用递增.计数器永远不会低于零,当acquire() ...