Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is the JavaScript code used for calling a webAPI controller in AJAX. But I got error returned. In this piece of code, an absolute URL is used. What's wrong the function fails? Thanks if you can help.
JavaScript
$('#btnSubmit').click(function (e) {
    $("#getResult").val("");
    debugger;
    var lon = getControlValue('txt_Lon');
    var lat = getControlValue('txt_Lat');
    var server_ = 'http://myServer/';
    server_ = server_ + "api/myController/GetLatlon?lon=" + lon + "&lat=" + lat;

    $.ajax({
        contentType: 'application/json',
        type: "GET",
        url: server_,
        success: function (result, textStatus, jqXHR) {
            debugger;
            setTextBoxValue('getResult', result.eligible);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            $("#getResult").val(jqXHR.statusText);
        }
    });
});


What I have tried:

How to call a webApi using an absolute URL?
Posted
Comments
David_Wimbley 29-Apr-19 23:09pm    
How do you expect us to know when thats not a real URL? We don't have access to your code, servers or your computer. You are going to need to be more specific in terms of "i got error returned".

First guess, your URL is wrong...so correct the URL.
s yu 30-Apr-19 7:50am    
The real URL is our company's address, not good to put here. Actually, I want to find a good sample I can refer to.
The error is:
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
It appears to be the access-related, nothing wrong in the code. Thanks.

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