0

Recently I encountered an issue with my TFS implementation. There is a WebService that is working perfectly if I use the Domain Address for TFS. "https://tfs.name.com/tfs".

However, if, internally, someone tries to use the local path: "https://servername:8080/tfs/" TFS works, but when the WebService enters the picture, it gives an error as such:

NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://tfs.name.com/TfsWebServices/TfsWorkItems.svc/"controldetails"'.

And the function the Extension is supposed to do is not executed. The address for the control, wit the "servername" path does not load as well.

The control has a function that depends on a path:

$.ajax({
            type: "GET",
            async: false,
            cache: false,
            contentType: "application/json",
            url: "https://tfs.name.com/TfsWebServices/TfsWorkItems.svc/Control",
            data: "datatypes"
            dataType: "json",
            processData: true,
            success:
                       function (response) {
                           result = response.GetResult;
                       },
            error:
                       function (XMLHttpRequest, textStatus, errorThrown) {
                           alert(errorThrown);
                       }
        });

I do believe it's a problem with Cross-Domain operations, but is it "Cross-Domain" since the "domain" for internal operations is the servername? Plus, normally it could be solved with the addition of a line on the website header, but TFS does not have a "Master" webpage, to my knowledge.

Has someone encountered a similar issue or a workaround for such a situation? I'm open to suggestions.

Thanks in advance!

Iceman
  • 463
  • 5
  • 14

1 Answers1

0

Yes this looks like a cross-domain issue.

As you are retrieving JSON you can get around this problem by making a JSONP request. Add

dataType: 'jsonp'

To your ajax settings object.

A great answer describing JSONP in more depth can be found here.

Community
  • 1
  • 1
Ben Smith
  • 19,589
  • 6
  • 65
  • 93
  • Hi! Thanks for your answer I tried with the first version of your answer and with this one, with no success. The latter one, hoewever, gave me a new error, in the Global Address, "jQuery -randomnumber- was not called" and in the Local Path, "Error 80020101" (IE) in Chrome, just gives "Unexpected Token". I also tried by reading the answer you linked, with no success. Tried adding "?callback=?" at the end of the URL, with "json: 'callback'" I do think there is something I'm missing, but according to your answer and the linked one, it should work with the modifications, right? – Iceman Jun 12 '14 at 09:13
  • Hmmm, reading up on JSONP and it states that the server needs to support JSONP. Do you have control of the TFS servers (i.e. can you modify them e.g. their config)? If so you "should" be able to enable [CORS](http://enable-cors.org/) and then what you have in your question should just work. – Ben Smith Jun 12 '14 at 09:36