MVC4 Web API RESTFUL服务 [英] MVC4 web api RESTFUL service
本文介绍了MVC4 Web API RESTFUL服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用js调用MVC4 Web API Restful服务?我在iis 7中托管了该服务.我尝试使用以下代码.
How to call a MVC4 web api restful services using js?. I hosted the service in iis 7. I tried with the following code.
<script>
$(function () {
debugger;
$.ajax({
url: 'http://172.16.0.110:80/vam/api/Asset/GetAllAssets',
data: '{"logInInfo":{"UserName":"eisg","Password":"M00s3h3ad"},"lastAssetIDInternal":"","lastSyncDate":"","startSyncDate":"" }',
type: 'POST',
dataType: 'json',
contentType: 'application/json',
fail: function (data) {
alert("aa");
alert("a");
}
});
});
</script>
.................................
........................
推荐答案
(调试器;
(function () { debugger;
.ajax({ 网址:' http://172.16.0.110:80/vam/api/Asset/GetAllAssets', 数据:' {"logInInfo":{"UserName":"eisg","Password":"M00s3h3ad"}, "lastAssetIDInternal":","lastSyncDate":","startSyncDate":"}', 类型:' POST', dataType:' json', contentType:' application/json', 失败:功能(数据){ alert(" ); alert(" ); } }); }); </script>
.ajax({ url: 'http://172.16.0.110:80/vam/api/Asset/GetAllAssets', data: '{"logInInfo":{"UserName":"eisg","Password":"M00s3h3ad"},"lastAssetIDInternal":"","lastSyncDate":"","startSyncDate":"" }', type: 'POST', dataType: 'json', contentType: 'application/json', fail: function (data) { alert("aa"); alert("a"); } }); }); </script>
........................
........................
这看起来像是跨域Ajax调用.那是做不到的.
如果包含javascript的html文件也托管在您的主机上,则只能执行此操作;
[^ ]
This looks like a cross domain ajax call. That can''t be done.
You can only do this if your html file which contains the javascript is also hosted on;
[^]
这篇关于MVC4 Web API RESTFUL服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文