Click here to Skip to main content
15,888,269 members
Home / Discussions / JavaScript
   

JavaScript

 
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 
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 
Hi Richard, The error messages I am now getting are Uncaught TypeError: Cannot read property 'lat' of undefined" and "Failed to load resource: the server responded with a status of 500 (Internal Server Error)".

Below is my code, global variables are declared but not initialized until the functions GetAddress() and GetClosestRestaurant() are called.
JavaScript
var _lat, _lng, _location, _distance, _results;
function GetClosestRestaurant(ilocation, idistance, iresults, callback) { 

        _lat = ilocation.lat();
        _lng = ilocation.lng(); 
        var jdata = { lat: _lat, lng: _lng, distance: idistance, results:iresults }; 
        var xhr = new XMLHttpRequest();

        xhr.onreadystatechange = function () {
            if (xhr.readyState < 4) { 
                return;
            }
            if (xhr.status !== 200) { 
                return;
            }
        };

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

    function GetAddress(addr, callback) {
     _location = "Some Location"; // Value returned from Google Map API
     _distance = "5";
     _results = "10";
    callback(_location, _distance, _results, GetClosestRestaurant);
    GetClosestRestaurant(_location, _distance, _results, DisplayClosestRestaurant); 
    }

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

The global variables _location, distance, and results are initialized in the function GetAddress(). Then the global variables _lat and _lng are both initialized in the GetClosestRestaurant().

I was able to show that all of them have a value by doing alerts so I am not seeing where I went wrong. Please point what I did incorrectly.

modified 16-Sep-15 15:42pm.

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 
GeneralRe: Callback is not a function error Pin
MadDashCoder16-Sep-15 9:33
MadDashCoder16-Sep-15 9:33 
GeneralRe: Callback is not a function error Pin
Richard MacCutchan16-Sep-15 21:26
mveRichard MacCutchan16-Sep-15 21:26 
QuestionJavascript and JQuery? Pin
Member 119720439-Sep-15 8:35
Member 119720439-Sep-15 8:35 
AnswerRe: Javascript and JQuery? Pin
Blikkies10-Sep-15 18:47
professionalBlikkies10-Sep-15 18:47 
AnswerRe: Javascript and JQuery? Pin
Member 1201497027-Sep-15 6:56
Member 1201497027-Sep-15 6:56 
AnswerRe: Javascript and JQuery? Pin
aarif moh shaikh1-Oct-15 0:32
professionalaarif moh shaikh1-Oct-15 0:32 
QuestionJavaScript runtime error: Unable to set property 'value' of undefined or null reference Pin
Rajesh_19808-Sep-15 10:00
Rajesh_19808-Sep-15 10:00 
AnswerRe: JavaScript runtime error: Unable to set property 'value' of undefined or null reference Pin
Richard Deeming14-Sep-15 3:41
mveRichard Deeming14-Sep-15 3:41 
QuestionAutomated Javascript Pin
Member 119664927-Sep-15 16:10
Member 119664927-Sep-15 16:10 
AnswerRe: Automated Javascript Pin
Peter Leow7-Sep-15 17:30
professionalPeter Leow7-Sep-15 17:30 
QuestionHow do I modify existing code to also hide/show controls under Justification for Request section? Pin
samflex4-Sep-15 7:33
samflex4-Sep-15 7:33 
QuestionGet Axis interval Pin
NJdotnetdev3-Sep-15 4:05
NJdotnetdev3-Sep-15 4:05 
QuestionRe: Get Axis interval Pin
Richard MacCutchan3-Sep-15 5:38
mveRichard MacCutchan3-Sep-15 5:38 
AnswerRe: Get Axis interval Pin
NJdotnetdev3-Sep-15 5:53
NJdotnetdev3-Sep-15 5:53 

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.