Click here to Skip to main content
12,635,428 members (24,244 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Javascript
hi,

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>


........................
Posted 10-Oct-12 0:32am
Updated 10-Oct-12 1:05am
Nelek111.1K
v4

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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;

[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100