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

JavaScript

 
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 
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 
Hi, thanks for replying. I have made changes to my code based on your suggestion and decided to use global variables as shown below.
JavaScript
_lat, _lng, _location, distance, results
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://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, DisplayClosestRestaurant);

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

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

Now I am getting the error "Uncaught TypeError: Cannot read property 'lat' of undefined" inside of the GetClosestRestaurant() function. I can't figure out why I am getting this error, since I get the value that I'm supposed to get when I do an alert passing in _lat. The other error I'm getting is "Failed to load resource: the server responded with a status of 500 (Internal Server Error)".

I'm not sure if it's related to the first error since I made sure the variable names passed to the web service match the names of the parameters inside the web service function being called.

Thanks again for your help.

modified 15-Sep-15 16:41pm.

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 
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 

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.