js跨域访问示例(客户端/服务端)
2014-05-19 00:00
501 查看
<div id="oid"></div> <script type="text/javascript"> //获取货号 $.ajax({ url: "http://192.168.1.191/H.ashx", type: "GET", dataType: 'jsonp', //jsonp的值自定义,如果使用jsoncallback,那么服务器端,要返回一个jsoncallback的值对应的对象. jsonp: 'jsoncallback', //要传递的参数,没有传参时,也一定要写上 data: null, timeout: 5000, //返回Json类型 contentType: "application/json;utf-8", //服务器段返回的对象包含name,openid. success: function (result) { document.getElementById('oid').innerText=result.name+":"+result.openid; }, error: function (jqXHR, textStatus, errorThrown) { alert(textStatus); } }); </script>
服务端 H.ashx
<%@ WebHandler Language="C#" Class="H" %> using System; using System.Web; public class H : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; string result = context.Request.QueryString["jsoncallback"] + "({\"name\":\"测试编号为\",\"openid\":\"123456789\"})"; context.Response.Clear(); context.Response.Write(result); context.Response.End(); } public bool IsReusable { get { return false; } } }
相关文章推荐
- js跨域访问示例(客户端/服务端)
- SharePoint 2013 APP 开发示例 (六)服务端跨域访问 Web Service (REST API)
- Asp.Net 客户端JS如何访问服务端控件的值?
- 客户端、服务端,跨域访问设置
- Asp.Net 客户端JS如何访问服务端控件的值?
- sharepoint form认证下跨域访问其他基本认证的系统(客户端用js的xmlhttprequest)的方法
- php SOAP客户端访问 JAVA soap服务端示例
- Asp.Net 客户端JS如何访问服务端控件的值
- html5客户端跨域访问php服务端数据
- linux下UDP 客户端和服务端程序示例
- js跨域访问
- 转贴:服务器端可控JS跨域访问解决方法
- FTP客户端访问用server-u构建的FTP服务端,中文显示为乱码的解决方法
- js跨域访问
- 跨域访问 js 使用json script 跨域访问
- Web客户端Js访问不同域中数据的解决方法
- js动态Script跨域访问
- js 跨域访问 找了好长时间
- 客户端js服务端互相调用
- 服务端/客户端 访问GridView中CheckBox的方法