×

Jquery 跨域访问 Lightswitch OData Service的方法

作者:Terry2017.02.02来源:Web前端之家浏览:9957评论:0
关键词:JQueryJS

.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>

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1485964800502.html

网友评论文明上网理性发言已有0人参与

发表评论: