Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code:

$.ajax({
type: 'GET',
url: 'http://localhost:51914/PlayerPortal/User/Test',
}).done(function (data) {
self.user(data.userName);
// Cache the access token in session storage.
sessionStorage.setItem(tokenKey, data.access_token);
}).fail(showError);

When I CTRL+click on the url above, the call works.
But when I run it through the webpage, I get
status: 0
statusText: error

How do I debug this? What could be wrong.
Sorry, I am very new to this.

What I have tried:

I have tried everything I can.

I can create a Web API 2 combined with MVC 5 in one solution, but I want separate solutions for each. I come from a WPF/WCF background.

I want a standalone Web API 2 solution and call it from a standalone MVC 5 solution.
Simple, right?
Posted
Updated 4-Jan-17 5:44am
v2
Comments
Pankaj Nikam 4-Jan-17 11:02am    
Is the application and the api on the same address?
Nick Van Tassell 4-Jan-17 11:23am    
No, they are separate solutions in separate web hosts.
Pankaj Nikam 4-Jan-17 11:35am    
I thought about it and I guess that it must be related to CORS. Not sure though.
F-ES Sitecore 4-Jan-17 11:14am    
Use the network tab of the browser debugging tools, and also the error console of the browser to see if any errors are happening. As mentioned in the other comment ajax calls only work by default to urls on the same domain so if this is not the case you'll get a CORS error, the solution for which is well documented so google it.
Nick Van Tassell 4-Jan-17 11:26am    
Oh yeah! I remember reading about CORS. Thank you.
Do most software shops split their MVC and Web API code into separate solutions or combine them as I have seen example of all over the web?

In the WPF/WCF world, we separate these concerns since CORS is not a problem.

1 solution

It IS due to CORS: Origin is defined by 1) host, 2) port, and 3) protocol
I guess I'll make it all in one app, like I've seen everywhere else.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900