How to break out of Jquery for iteration [closed] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Is there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How do I redirect to another webpage?How can I know which radio button is selected via jQuery?How to check whether a checkbox is checked in jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?
Is it possible for SQL statements to execute concurrently within a single session in SQL Server?
Should a wizard buy fine inks every time he want to copy spells into his spellbook?
Strange behavior of Object.defineProperty() in JavaScript
Most bit efficient text communication method?
What does 丫 mean? 丫是什么意思?
Dyck paths with extra diagonals from valleys (Laser construction)
How would a mousetrap for use in space work?
Tannaka duality for semisimple groups
What does this say in Elvish?
What does Turing mean by this statement?
What is the difference between a "ranged attack" and a "ranged weapon attack"?
Is there public access to the Meteor Crater in Arizona?
Why weren't discrete x86 CPUs ever used in game hardware?
How to identify unknown coordinate type and convert to lat/lon?
How to write capital alpha?
Would it be easier to apply for a UK visa if there is a host family to sponsor for you in going there?
Do wooden building fires get hotter than 600°C?
What is the chair depicted in Cesare Maccari's 1889 painting "Cicerone denuncia Catilina"?
Why does 14 CFR have skipped subparts in my ASA 2019 FAR/AIM book?
An adverb for when you're not exaggerating
Drawing spherical mirrors
Intuitive explanation of the rank-nullity theorem
Project Euler #1 in C++
Flash light on something
How to break out of Jquery for iteration [closed]
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Is there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How do I redirect to another webpage?How can I know which radio button is selected via jQuery?How to check whether a checkbox is checked in jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a situation that I am using AJAX to call a page that returns a list of business locations to populate a Google map. My original goal was to display markers for locations whose radius touched the website visitor's location.
Now I only need to know IF the website visitor is within the radius of any one of the locations returned by the ajax call. In the code below, you see a conditional statement "fink <= rs.Records[recno].radius". What I am attempting to do is the first time that statement executes to true, set a cookie and/or call a function and exit the for loop.
As a side question, a friend told me of something called grep (I think). Do I need to loop through an entire list to find if that condition is true? Meaning I know in mySQL I can just query something like "select * from locations where radius < 50". So if my ajax returns 10,000 locations, all I need to know is my website visitor distance within the radius of any any of my locations?
Thanks in advance for any help.
function distance(lat1, lon1, lat2, lon2)
var p = 0.017453292519943295; // Math.PI / 180
var c = Math.cos;
var a = 0.5 - c((lat2 - lat1) * p) / 2 +
c(lat1 * p) * c(lat2 * p) *
(1 - c((lon2 - lon1) * p)) / 2;
return .62137119 * (12742 * Math.asin(Math.sqrt(a))); // 2 * R; R = 6371 km
function getMarkers(lat, lng, city, state)
$.ajax(
url: '/getMarkers.asp?state=Nebraska',
type: 'GET',
dataType: 'text',
error: function(xhr, status, errorstr)
console.log(errorstr); // just show error message in console if there was an error
,
).done(function(response_obj)
console.log(response_obj);
var rs = eval(response_obj);
if (rs) // has a non-null value
var str = rs.RecordCount + " Users:<br/>";
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
initMap();
else
str = "No users found"
);
jquery
closed as unclear what you're asking by Kevin B, Devon_C_Miller, Zoe, webwurst, Dale Burrell Mar 9 at 5:03
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have a situation that I am using AJAX to call a page that returns a list of business locations to populate a Google map. My original goal was to display markers for locations whose radius touched the website visitor's location.
Now I only need to know IF the website visitor is within the radius of any one of the locations returned by the ajax call. In the code below, you see a conditional statement "fink <= rs.Records[recno].radius". What I am attempting to do is the first time that statement executes to true, set a cookie and/or call a function and exit the for loop.
As a side question, a friend told me of something called grep (I think). Do I need to loop through an entire list to find if that condition is true? Meaning I know in mySQL I can just query something like "select * from locations where radius < 50". So if my ajax returns 10,000 locations, all I need to know is my website visitor distance within the radius of any any of my locations?
Thanks in advance for any help.
function distance(lat1, lon1, lat2, lon2)
var p = 0.017453292519943295; // Math.PI / 180
var c = Math.cos;
var a = 0.5 - c((lat2 - lat1) * p) / 2 +
c(lat1 * p) * c(lat2 * p) *
(1 - c((lon2 - lon1) * p)) / 2;
return .62137119 * (12742 * Math.asin(Math.sqrt(a))); // 2 * R; R = 6371 km
function getMarkers(lat, lng, city, state)
$.ajax(
url: '/getMarkers.asp?state=Nebraska',
type: 'GET',
dataType: 'text',
error: function(xhr, status, errorstr)
console.log(errorstr); // just show error message in console if there was an error
,
).done(function(response_obj)
console.log(response_obj);
var rs = eval(response_obj);
if (rs) // has a non-null value
var str = rs.RecordCount + " Users:<br/>";
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
initMap();
else
str = "No users found"
);
jquery
closed as unclear what you're asking by Kevin B, Devon_C_Miller, Zoe, webwurst, Dale Burrell Mar 9 at 5:03
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
break
will break out of a loop.
– Barmar
Mar 8 at 21:58
"set a cookie and/or call a function and exit the for loop." i see where you called .append, but, i don't see where you tried setting a cookie and/or exiting the loop.
– Kevin B
Mar 8 at 21:59
BTW, don't useeval(response_obj)
, useJSON.parse(response_obj)
.
– Barmar
Mar 8 at 22:03
add a comment |
I have a situation that I am using AJAX to call a page that returns a list of business locations to populate a Google map. My original goal was to display markers for locations whose radius touched the website visitor's location.
Now I only need to know IF the website visitor is within the radius of any one of the locations returned by the ajax call. In the code below, you see a conditional statement "fink <= rs.Records[recno].radius". What I am attempting to do is the first time that statement executes to true, set a cookie and/or call a function and exit the for loop.
As a side question, a friend told me of something called grep (I think). Do I need to loop through an entire list to find if that condition is true? Meaning I know in mySQL I can just query something like "select * from locations where radius < 50". So if my ajax returns 10,000 locations, all I need to know is my website visitor distance within the radius of any any of my locations?
Thanks in advance for any help.
function distance(lat1, lon1, lat2, lon2)
var p = 0.017453292519943295; // Math.PI / 180
var c = Math.cos;
var a = 0.5 - c((lat2 - lat1) * p) / 2 +
c(lat1 * p) * c(lat2 * p) *
(1 - c((lon2 - lon1) * p)) / 2;
return .62137119 * (12742 * Math.asin(Math.sqrt(a))); // 2 * R; R = 6371 km
function getMarkers(lat, lng, city, state)
$.ajax(
url: '/getMarkers.asp?state=Nebraska',
type: 'GET',
dataType: 'text',
error: function(xhr, status, errorstr)
console.log(errorstr); // just show error message in console if there was an error
,
).done(function(response_obj)
console.log(response_obj);
var rs = eval(response_obj);
if (rs) // has a non-null value
var str = rs.RecordCount + " Users:<br/>";
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
initMap();
else
str = "No users found"
);
jquery
I have a situation that I am using AJAX to call a page that returns a list of business locations to populate a Google map. My original goal was to display markers for locations whose radius touched the website visitor's location.
Now I only need to know IF the website visitor is within the radius of any one of the locations returned by the ajax call. In the code below, you see a conditional statement "fink <= rs.Records[recno].radius". What I am attempting to do is the first time that statement executes to true, set a cookie and/or call a function and exit the for loop.
As a side question, a friend told me of something called grep (I think). Do I need to loop through an entire list to find if that condition is true? Meaning I know in mySQL I can just query something like "select * from locations where radius < 50". So if my ajax returns 10,000 locations, all I need to know is my website visitor distance within the radius of any any of my locations?
Thanks in advance for any help.
function distance(lat1, lon1, lat2, lon2)
var p = 0.017453292519943295; // Math.PI / 180
var c = Math.cos;
var a = 0.5 - c((lat2 - lat1) * p) / 2 +
c(lat1 * p) * c(lat2 * p) *
(1 - c((lon2 - lon1) * p)) / 2;
return .62137119 * (12742 * Math.asin(Math.sqrt(a))); // 2 * R; R = 6371 km
function getMarkers(lat, lng, city, state)
$.ajax(
url: '/getMarkers.asp?state=Nebraska',
type: 'GET',
dataType: 'text',
error: function(xhr, status, errorstr)
console.log(errorstr); // just show error message in console if there was an error
,
).done(function(response_obj)
console.log(response_obj);
var rs = eval(response_obj);
if (rs) // has a non-null value
var str = rs.RecordCount + " Users:<br/>";
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
initMap();
else
str = "No users found"
);
jquery
jquery
edited Mar 8 at 21:57
Barmar
438k36262366
438k36262366
asked Mar 8 at 21:55
TMHDesignTMHDesign
34118
34118
closed as unclear what you're asking by Kevin B, Devon_C_Miller, Zoe, webwurst, Dale Burrell Mar 9 at 5:03
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Kevin B, Devon_C_Miller, Zoe, webwurst, Dale Burrell Mar 9 at 5:03
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
break
will break out of a loop.
– Barmar
Mar 8 at 21:58
"set a cookie and/or call a function and exit the for loop." i see where you called .append, but, i don't see where you tried setting a cookie and/or exiting the loop.
– Kevin B
Mar 8 at 21:59
BTW, don't useeval(response_obj)
, useJSON.parse(response_obj)
.
– Barmar
Mar 8 at 22:03
add a comment |
break
will break out of a loop.
– Barmar
Mar 8 at 21:58
"set a cookie and/or call a function and exit the for loop." i see where you called .append, but, i don't see where you tried setting a cookie and/or exiting the loop.
– Kevin B
Mar 8 at 21:59
BTW, don't useeval(response_obj)
, useJSON.parse(response_obj)
.
– Barmar
Mar 8 at 22:03
break
will break out of a loop.– Barmar
Mar 8 at 21:58
break
will break out of a loop.– Barmar
Mar 8 at 21:58
"set a cookie and/or call a function and exit the for loop." i see where you called .append, but, i don't see where you tried setting a cookie and/or exiting the loop.
– Kevin B
Mar 8 at 21:59
"set a cookie and/or call a function and exit the for loop." i see where you called .append, but, i don't see where you tried setting a cookie and/or exiting the loop.
– Kevin B
Mar 8 at 21:59
BTW, don't use
eval(response_obj)
, use JSON.parse(response_obj)
.– Barmar
Mar 8 at 22:03
BTW, don't use
eval(response_obj)
, use JSON.parse(response_obj)
.– Barmar
Mar 8 at 22:03
add a comment |
1 Answer
1
active
oldest
votes
Use break;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
break;
And if you want to know if any were found, you can set a variable.
found_close = false;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
found_close = true;
break;
if (!found_close)
// do something
Thanks for taking the time to help me. Seems that given a situation where you might have 10,000 locations, and maybe hitting true on 9,999, there would be a way to get a quicker answer than a loop. Have a great day.
– TMHDesign
Mar 8 at 22:51
You might be able to improve the database query, by calculating the distance there, then usingORDER BY DISTANCE LIMIT 1
.
– Barmar
Mar 8 at 22:57
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use break;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
break;
And if you want to know if any were found, you can set a variable.
found_close = false;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
found_close = true;
break;
if (!found_close)
// do something
Thanks for taking the time to help me. Seems that given a situation where you might have 10,000 locations, and maybe hitting true on 9,999, there would be a way to get a quicker answer than a loop. Have a great day.
– TMHDesign
Mar 8 at 22:51
You might be able to improve the database query, by calculating the distance there, then usingORDER BY DISTANCE LIMIT 1
.
– Barmar
Mar 8 at 22:57
add a comment |
Use break;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
break;
And if you want to know if any were found, you can set a variable.
found_close = false;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
found_close = true;
break;
if (!found_close)
// do something
Thanks for taking the time to help me. Seems that given a situation where you might have 10,000 locations, and maybe hitting true on 9,999, there would be a way to get a quicker answer than a loop. Have a great day.
– TMHDesign
Mar 8 at 22:51
You might be able to improve the database query, by calculating the distance there, then usingORDER BY DISTANCE LIMIT 1
.
– Barmar
Mar 8 at 22:57
add a comment |
Use break;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
break;
And if you want to know if any were found, you can set a variable.
found_close = false;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
found_close = true;
break;
if (!found_close)
// do something
Use break;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
break;
And if you want to know if any were found, you can set a variable.
found_close = false;
for (var recno = 0; recno < rs.RecordCount; recno++)
fink = distance(<%= session("uLat") %>, <%= session("uLng") %>, rs.Records[recno].latitude, rs.Records[recno].longitude);
if (fink <= rs.Records[recno].radius)
$(".markers").append("<li data-center='" + rs.Records[recno].latitude + ", " + rs.Records[recno].longitude + "' data-locale='" + recno + "' data-radius='" + rs.Records[recno].radius + "' data-location='" + rs.Records[recno].city + "'>" + rs.Records[recno].street + "</li>n");
found_close = true;
break;
if (!found_close)
// do something
answered Mar 8 at 22:05
BarmarBarmar
438k36262366
438k36262366
Thanks for taking the time to help me. Seems that given a situation where you might have 10,000 locations, and maybe hitting true on 9,999, there would be a way to get a quicker answer than a loop. Have a great day.
– TMHDesign
Mar 8 at 22:51
You might be able to improve the database query, by calculating the distance there, then usingORDER BY DISTANCE LIMIT 1
.
– Barmar
Mar 8 at 22:57
add a comment |
Thanks for taking the time to help me. Seems that given a situation where you might have 10,000 locations, and maybe hitting true on 9,999, there would be a way to get a quicker answer than a loop. Have a great day.
– TMHDesign
Mar 8 at 22:51
You might be able to improve the database query, by calculating the distance there, then usingORDER BY DISTANCE LIMIT 1
.
– Barmar
Mar 8 at 22:57
Thanks for taking the time to help me. Seems that given a situation where you might have 10,000 locations, and maybe hitting true on 9,999, there would be a way to get a quicker answer than a loop. Have a great day.
– TMHDesign
Mar 8 at 22:51
Thanks for taking the time to help me. Seems that given a situation where you might have 10,000 locations, and maybe hitting true on 9,999, there would be a way to get a quicker answer than a loop. Have a great day.
– TMHDesign
Mar 8 at 22:51
You might be able to improve the database query, by calculating the distance there, then using
ORDER BY DISTANCE LIMIT 1
.– Barmar
Mar 8 at 22:57
You might be able to improve the database query, by calculating the distance there, then using
ORDER BY DISTANCE LIMIT 1
.– Barmar
Mar 8 at 22:57
add a comment |
break
will break out of a loop.– Barmar
Mar 8 at 21:58
"set a cookie and/or call a function and exit the for loop." i see where you called .append, but, i don't see where you tried setting a cookie and/or exiting the loop.
– Kevin B
Mar 8 at 21:59
BTW, don't use
eval(response_obj)
, useJSON.parse(response_obj)
.– Barmar
Mar 8 at 22:03