.net代码
复制代码 代码如下:
<system.webServer>
    ......
    ....
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Max-Age" value="3600" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept, MaxDataServiceVersion" />
<add name="Access-Control-Allow-Methods" value="PUT, POST, GET, DELETE, MERGE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer> 


Jquery客户端测试代码

复制代码 代码如下:
<script  type="text/javascript">
         $(document).ready(function () {
             $(":button").on("click", function(event){
                 //alert( $(this).attr('value'));
                 var url = "http://localhost:2401/ApplicationData.svc/Records";
                 $.getJSON(url, function (data) {
                     var items = [];
                     var values = data.value;
                     $.each(values, function (key, val) {

                         items.push('<li id="' + key + '">' + val.Name + '</li>');
                     });

                     $('<ul/>', {
                         'class': 'my-new-list',
                         html: items.join('')
                     }).appendTo('#mylist');
                 });
             });
         });
    </script>

标签:
Jquery,跨域访问,asp.net

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com