1、配置

web.config

<webServices>
<!--必须添加-->
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices> <httpModules>
<add name="JsonpHttpModule" type="MJN.Common.JsonpHttpModule" />
</httpModules>

webservice.asmx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using MJN.Common; namespace MJN
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string getTime()
{
ResonseMessage result = new ResonseMessage()
{
state = "1",
msg = new Random().Next(1, 10000).ToString()
};
return result.ToJson();
} }
}

 

angularjs

services.factory('httpService', ['$resource', '$http', '$q', '$templateCache',
function ($resource, $http, $q, $templateCache) {
return {
setting: function (url, data) {
var deferred = $q.defer();
method = (url.indexOf('http') > -1) ? 'JSONP' : 'POST';
$http({
method: method,
url: url,
cache: $templateCache,
data: data
//headers: { 'Content-Type': 'application/json;charset=UTF-8' }
//headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }
}).success(function (data, status, headers, config) {
deferred.resolve(data, status, headers, config);
}).error(function (data, status, headers, config) {
deferred.reject("network error");
});
return deferred.promise;
}
};
} ]);

  

调用:

httpService.setting('http://10.20.26.19/mjn/WebService1.asmx/getTime?callback=JSON_CALLBACK&format=jsonp&t=' + new Date().getTime()).then(function (data, status, headers, config) {
console.log(data);
}, function (reason) {
console.log(reason);
});

  

 

angularjs跨域调取webservice的更多相关文章

  1. 浅谈跨域以及WebService对跨域的支持

    跨域问题来源于JavaScript的同源策略,即只有 协议+主机名+端口号 (如存在)相同,则允许相互访问.也就是说JavaScript只能访问和操作自己域下的资源,不能访问和操作其他域下的资源. 在 ...

  2. 浅谈跨域以WebService对跨域的支持

    跨域问题来源于JavaScript的同源策略,即只有 协议+主机名+端口号 (如存在)相同,则允许相互访问.也就是说JavaScript只能访问和操作自己域下的资源,不能访问和操作其他域下的资源. 在 ...

  3. jQuery跨域调用WebService

    jQuery跨域调用WebService举例html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...

  4. 跨域以及WebService对跨域的支持

    无耻收藏该博主的成果啦!https://www.cnblogs.com/yangecnu/p/introduce-cross-domain.html 通过域验证访问WebService:https:/ ...

  5. jquery+ajax跨域请求webservice

    最近几天在学习webservice...在学习的时候便想到用ajax的方式去请求webservice.. 一直在测试..如果这个被请求的webservice和自己使用的是同一个端口号.则不用考虑那aj ...

  6. AngularJS跨域请求

    本文主要针对网上各种跨域请求的总结,并加入自己的验证判断,实现工作中遇到的跨域问题.所涉及到的领域很小,仅仅局限于:AngularJS CORS post 并同时需要实现json数据传送给服务器. 首 ...

  7. 跨域调用webservice

    本人第一次在博客园写博客. 最近研究js的跨域调用,举个小例子. ASP.net 中webservice 源代码 /// <summary>    /// Service1 的摘要说明   ...

  8. Angularjs跨域

    一.首先我们要明白跨域的字面概念,读过留过印象之后,下面将会有例子进一步解释 有一篇文章<跨域的理解与实现>描述得很清楚,在这里摘录如下: 域(Domain)是Windows网络中独立运行 ...

  9. angularjs跨域post解决方案

    转自:http://www.thinksaas.cn/topics/0/34/34536.html 前端同学李雷和后台同学韩梅梅分别在自己电脑上进行开发,后台接口写好的时候,李雷改动完就把前端代码上传 ...

随机推荐

  1. ldr指令总结

    LDR/STR字和无符号字节加载/存储 1,LDR Rd,[Rn]   2, LDR Rd,[Rn,Flexoffset] 3, LDR Rd,[Rn],Flexoffset 4, LDR Rd,la ...

  2. Hdu 4311-Meeting point-1 曼哈顿距离,前缀和

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4311 Meeting point-1 Time Limit: 2000/1000 MS (Java/Oth ...

  3. mv、umask、chattr、lsattr命令

    mv命令行,即move 将文件移动到目录下 对文件或目录重命名 umask chattr 设置文件或目录的隐藏属性 lsattr显示文件或目录的隐藏属性 ls mv 1.txt aa ls cd aa ...

  4. 让你的Xcode8 支持 iOS7

    Xcode8 发布,更新后,发现支持从iOS8开始,可是公司要求从iOS7开始,,,这和苹果相悖. 不过没关系. 跳转 www.cnblogs.com/starainDou/p/5325643.htm ...

  5. pci转并口卡的安装使用

    pci转并口卡模拟出来的并口并不能完全等同于主板上真正的并口.真正的并口打印的时候可以“直接瓶口输出”打印,而不需要安装打印驱动程序. 这个模拟出来的并口却不能使用“直接瓶口输出”(打印机不打印,程序 ...

  6. swift小结01--基础篇

    2014年推出的swift目前已来到了3.0,日趋稳定,这个是之前学习整理的关于swift的资料,分享给大家,希望有用,写的不足的地方还请见谅. 语言背景:         Swift 语言由苹果公司 ...

  7. NPOI组件集锦

    关于NPOI不错的介绍:http://www.cnblogs.com/restran/p/3889479.html http://www.cnblogs.com/Irving/archive/2012 ...

  8. 【转】Android Studio 的小小配置

    这篇博文的内容列表: 1.编辑器的字体设置 2.预览XML布局 3.导入项目  4.显示行号  5.新建Java类和Component的子类 额~~程序猿一般话都不多,嘿嘿,那咱就直接图文吧~ ^_^ ...

  9. 日志分析(php+nosql+rsync+crontable)

    是不是经常要分析用户的行为?是不是经常遇到多台server上传的日志一起分析?是不是对数据统计的间隔时间要求非常短?还有木有由于日志文件过大,而须要分块处理? 1.说明一点在日志写入的时候必须依照一种 ...

  10. 如何在客户端配置ODBC来访问远程DB2 for Windows服务器

    如何在客户端配置ODBC来访问远程DB2 for Windows服务器                                  马根峰                    (广东联合电子服 ...