Click here to Skip to main content
15,909,440 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Difference between Two dates Pin
DanielBrownAU28-Sep-15 14:13
professionalDanielBrownAU28-Sep-15 14:13 
QuestionArrays Pin
Member 1201551027-Sep-15 16:15
Member 1201551027-Sep-15 16:15 
QuestionRe: Arrays Pin
Blikkies28-Sep-15 19:55
professionalBlikkies28-Sep-15 19:55 
AnswerRe: Arrays Pin
User 118621168-Nov-15 20:10
User 118621168-Nov-15 20:10 
Questionneed help Pin
Member 1197204327-Sep-15 4:09
Member 1197204327-Sep-15 4:09 
AnswerRe: need help Pin
Richard MacCutchan27-Sep-15 4:23
mveRichard MacCutchan27-Sep-15 4:23 
AnswerRe: need help Pin
Nathan Minier1-Oct-15 6:39
professionalNathan Minier1-Oct-15 6:39 
GeneralRe: need help Pin
Member 119720431-Oct-15 8:10
Member 119720431-Oct-15 8:10 
GeneralRe: need help Pin
Member 1197204310-Oct-15 11:15
Member 1197204310-Oct-15 11:15 
GeneralRe: need help Pin
Nathan Minier13-Oct-15 1:23
professionalNathan Minier13-Oct-15 1:23 
QuestionSet up a counter to count the number of times an alert is triggered in a website. Pin
Rajesh_198025-Sep-15 9:18
Rajesh_198025-Sep-15 9:18 
AnswerRe: Set up a counter to count the number of times an alert is triggered in a website. Pin
Wombaticus8-Oct-15 1:25
Wombaticus8-Oct-15 1:25 
Questionhow to perform color effect on image in imagemagick? Pin
Rajiv Rahi24-Sep-15 2:24
professionalRajiv Rahi24-Sep-15 2:24 
QuestionCannot get dynamic javascript content from web page Pin
elelont223-Sep-15 3:08
elelont223-Sep-15 3:08 
AnswerRe: Cannot get dynamic javascript content from web page Pin
Richard MacCutchan23-Sep-15 3:51
mveRichard MacCutchan23-Sep-15 3:51 
QuestionCallback is not a function error Pin
MadDashCoder14-Sep-15 21:36
MadDashCoder14-Sep-15 21:36 
Hi all, I am trying to call to a web service in a function but I get 2 errors that I cannot figure out the cause.

The first error is "Uncaught ReferenceError: distance is not defined" and the second error is "Uncaught TypeError: callback is not a function".

The following is my code snippet
JavaScript
function GetClosestRestaurant(location, distance, results, callback) {

        _lat = location.lat();
        _lng = location.lng();

        var jdata = { lat: _lat, lng: _lng, distance: distance, results:results };

        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState < 4) {

                return;
            }
            if (xhr.status !== 200) {

                return;
            }
        };

        xhr.open('Get', 'http://http://localhost:21311/myService.asmx/GetClosestPlace', true);
        xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

        xhr.send(JSON.stringify(jdata));
        callback(xhr.responseText);
    }

    GetClosestRestaurant(location, distance, results, DisplayPlace);

    function GetAddress(addr, callback) {
    var location = "Some Location"; // Value returned from Google Map API
    var distance = "5";
    var results = "10";
    callback(location, distance, results);
    }

    function GetLatLong() {
      var address = "123 SomeStreet, SomeCity, SomeState";
       GetAddress(address, GetClosestRestaurant)
    }

I made sure that the variables location, distance, and results all have values by doing alert on all of them inside of the GetClosestRestaurant() function definition.

when I call GetClosestRestaurant() however, I get the error as stated above. Any help is greatly appreciated, thanks in advance.

modified 15-Sep-15 14:48pm.

AnswerRe: Callback is not a function error Pin
Richard Deeming15-Sep-15 2:06
mveRichard Deeming15-Sep-15 2:06 
GeneralRe: Callback is not a function error Pin
MadDashCoder15-Sep-15 6:39
MadDashCoder15-Sep-15 6:39 
GeneralRe: Callback is not a function error Pin
Richard MacCutchan15-Sep-15 9:09
mveRichard MacCutchan15-Sep-15 9:09 
GeneralRe: Callback is not a function error Pin
MadDashCoder15-Sep-15 10:40
MadDashCoder15-Sep-15 10:40 
GeneralRe: Callback is not a function error Pin
Richard MacCutchan15-Sep-15 10:45
mveRichard MacCutchan15-Sep-15 10:45 
GeneralRe: Callback is not a function error Pin
MadDashCoder15-Sep-15 14:21
MadDashCoder15-Sep-15 14:21 
GeneralRe: Callback is not a function error Pin
Richard MacCutchan15-Sep-15 21:20
mveRichard MacCutchan15-Sep-15 21:20 
GeneralRe: Callback is not a function error Pin
MadDashCoder15-Sep-15 23:29
MadDashCoder15-Sep-15 23:29 
GeneralRe: Callback is not a function error Pin
Richard MacCutchan16-Sep-15 0:01
mveRichard MacCutchan16-Sep-15 0:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.