Jquery 跨域访问 Lightswitch OData Service的方法

复制代码 代码如下:


<system.webServer>
    ......
    ....
<httpProtocol>
<customHeaders>
<add value="*" />
<add value="3600" />
<add value="Content-Type, Accept, MaxDataServiceVersion" />
<add 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>' + val.Name + '</li>');
                     });

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

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdzjxp.html