0

Today, I wrote my very first ASP MVC WebService (.Net version 4, Entity4.2). It's really simple and just returns back an array of custom ItemChoice objects. When I call it directly from IE, it wants to download the json objects, and when I call it from FF, I see the XML version of the objects.

I'm working on integrating the web service into a page I'm building on localhost (to start), using the jquery 1.7.1 that ships with VS 12.

What happens when I call the service from JQuery is that the success function never runs. However, if I point getJSON to the local copy of the same service, it works. Looking at Charles Web Proxy, both come back and appear to have identical returns.

The code looks like this:

<script type="text/javascript">
    $(document).ready(function() {
        $.getJSON('http://myserver/CECService/api/itemchoices',
            function (data, status) {
                $.each(data, function(key, val) {
                    $('<option />', {value:val.itemValue, text:val.displayText}).appendTo('#School');

                });//end each
            });//end get json
    });//end document.ready
</script>

1 Answer 1

3

You're experiencing this issue, because you are making an ajax call which violates the browser's same origin security policy. See the following for an explanation of potential a work around.

EDIT:

Another often used approach is JSONP.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I haven't needed to do this stuff in so long, I'd forgotten about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.