-1

I've build an WebAPI (.net) application and a simple HTML website for the front-end. Everything worked fine when executing via Visual Studio.

When I tried use this application in my host server, I did sucefully send (POST) a complex object via JSON to the webapi (login) and to "GET" complex objects (User info, configurations, etc...)

But, when I tried to perform a "GET" to obtain a list of object, the server respond: 500 - failed to execute 'send' on 'xmlhttprequest': failed to load '<link to my service>'.

In Resume: GET and POST using objects goes fine GET a list of objects goes bad.

What do I do?

CODE:

function GetService(urlFunc) {

var ret = null;

$.ajax({
    url: urlFunc,
    type: 'GET',
    dataType: 'json',
    async: false,
    crossDomain: true,
    success: function (msg) {
        ret = msg;
    },
    error: function (msg) {
        //LOG EVENTS
        ret = false;
    }
});

return ret;

};

  • Where is your code?! – eisbehr Jan 29 '18 at 15:39
  • 1
    It would help if you post the code where the error is occurring (maybe start with the JavaScript first) – Matthew Groves Jan 29 '18 at 15:40
  • Sorry guys. Updated the code – Anderson Tavares Jan 29 '18 at 15:52
  • You **never** want to make `async: false` Ajax requests. Forget that the feature even exists. – Tomalak Jan 29 '18 at 16:01
  • Read https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call ("How do I return the response from an asynchronous call?") – Tomalak Jan 29 '18 at 16:03
  • Is the URL you're using correct for the new environment? And yeah `async:false` = bad. Horrible user experience (locks the browser UI during ajax requests), and lets you get away with bad habits regarding callbacks (see Tomalak's link). Also it's deprecated. – ADyson Jan 29 '18 at 16:47
  • what does urlFunc equal? this is probably your problem. – theHaggis Jan 29 '18 at 16:48
  • Hi guys. About the async: false In this case, I think that is necessary because is part of login process. But I will read the article later and see if works in my case. The UrlFunc is the Url of the WebApi. This is a method used by many functions. The URL is correct, and like I said before, when debugging on visual studio, this method works fine! The problem is when I call the WebAPI Published on the host – Anderson Tavares Jan 30 '18 at 10:00
  • "I think that is necessary because is part of login process", can you explain why? I can't think of a good reason why it would be important. "The URL is correct"...give us an example of the URL please. I would assume that, when you deployed it, the URL is no longer correct for the new environment. Based on the information available to us, that seems to be the most likely explanation. Failing that, something in the API is crashing, and you need to check your server logs to find the cause. – ADyson Jan 30 '18 at 10:34
  • hi guys! I found the problem. Actually it was in the webapi. It was not sending (for some reason) the list in Json. When I changed the type of Return (For an array, by example), the AJAX receive the list normally. Now I have to discover how to config the webapi to send the list of objects. Thanks everyone! I will change the code for remove the async too! – Anderson Tavares Feb 02 '18 at 08:11

1 Answers1

0

I found the problem. Actually it was in the webapi. It was not sending (for some reason) the list in Json. When I changed the type of Return (For an array, by example), the AJAX receive the list normally. Now I have to discover how to config the webapi to send the list of objects. Thanks everyone! I will change the code for remove the async too!