Topic: Append parameters to async link onclick before request is sent

Hello,

I have an async link that is for "Find Locations Near Me".  At the time the user clicks on the link I would like to append the latitude & longitude params to the URL before the request is sent using geolocation APIs. 

I would like to do this at that time only so that the user gets the "allow to use current location" popup only once they click the link. 

What is the best way to accomplish this?  It seems that trying to change the URL in the beginsync or willsync events is too late.

Please advise.  Thanks...


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Re: Append parameters to async link onclick before request is sent

Ok, I will fix this. Thanks!

We need Amazon reviewers. Please do one!
Book: "Beginning iPhone and iPad Web Apps: Scripting with HTML5, CSS3, and JavaScript" Buy Now! (or review).
/!\ Don't forget to "Like" WebApp.Net from the homepage

Re: Append parameters to async link onclick before request is sent

Chrilith,

Could you think of a work around in the mean time or how long it may take to fix?  How could I use WebApp.Request to do the same thing?

If you are making a fix are you planning on changing it so that we will handle an event and then change the URL via the context object before the request is sent out?

Thanks...

Re: Append parameters to async link onclick before request is sent

Already fixed locally. I'll send you a new version with this feature (using beginasync event)

We need Amazon reviewers. Please do one!
Book: "Beginning iPhone and iPad Web Apps: Scripting with HTML5, CSS3, and JavaScript" Buy Now! (or review).
/!\ Don't forget to "Like" WebApp.Net from the homepage

Re: Append parameters to async link onclick before request is sent

Chrilith,

Wow that's fast!  How will you send it?

Much appreciated.  Thanks..

Re: Append parameters to async link onclick before request is sent

Sent by email!

We need Amazon reviewers. Please do one!
Book: "Beginning iPhone and iPad Web Apps: Scripting with HTML5, CSS3, and JavaScript" Buy Now! (or review).
/!\ Don't forget to "Like" WebApp.Net from the homepage

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Re: Append parameters to async link onclick before request is sent

About geolocation, are you using the new safari builtin feature introduced in v3.0?

There is a good article about this http://fvisticot.blogspot.com/2009/05/l … owser.html

We need Amazon reviewers. Please do one!
Book: "Beginning iPhone and iPad Web Apps: Scripting with HTML5, CSS3, and JavaScript" Buy Now! (or review).
/!\ Don't forget to "Like" WebApp.Net from the homepage

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Re: Append parameters to async link onclick before request is sent

I'm using the 0.5 release.

I have the same pb to add extra parameters in the XmlHttpRequest before the request is sent to the server.
I don't know how to do that:

I have added the listener:

WebApp.AddEventListener("beginasync", beginasync);

In the beginasyn handler i have added the following code:

modifiedUrl = currentUrl + "&newParam=33"
req=evtObj.target;
req.open("GET", modifiedUrl, true);

Is it the way to add parameters in the XmlHttpRequest ?

because for me, it does not work...

I see in that post that you have an answer...can you provide me the patch as well

Thank you to for refering to my blog for location feature smile

Fred


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Re: Append parameters to async link onclick before request is sent

You're welcome wink.

Now, for beginasync, quite easy. Here a sample handler:

function myHandler(evt) {
    var url = evt.context[0];
    // do something with url...
    evt.context[0] = url;
}

That's it! I think the feature is in RC5, else take the Logic.js file from the demo here http://demo.webapp-net.com

We need Amazon reviewers. Please do one!
Book: "Beginning iPhone and iPad Web Apps: Scripting with HTML5, CSS3, and JavaScript" Buy Now! (or review).
/!\ Don't forget to "Like" WebApp.Net from the homepage

Re: Append parameters to async link onclick before request is sent

I had the same problem and I got another workaround.

The original link looked like this:
<a id="link1" href="#_Results" rev="async">Some text</a>

then I added javascript for safari's geolocation object:
navigator.geolocation.getCurrentPosition(createMap, handleError);

and in CreateMap which is the function that called after successful geo-lookup I added:
document.getElementById('link1').href="geodata_processor.php?lat="+position.coords.latitude + "&lng=" + position.coords.longitude + "#_Results";

so once the coordinate obtained, the link changes.


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Re: Append parameters to async link onclick before request is sent

So, has anyone got this to work? I have tried so many different solution and cannot find a good solution! Basically the geo-location lookup seems to take so long that the asynchronous event doesn't wait for it or sometimes it just doesn't go anywhere and you have to click again!

Currently, my code looks like this:

<li><a href="#_RVDealers" id="memberLocationLink" onclick="memberGeoLoc();" rev="async">Use My Location</a></li>

Then, I have this:

function beginasync(evtObj) {
    var url = evtObj.context[0];
    if (url.indexOf("rv-dealers.ashx") >= 0) {
        memberGeoLoc();
    }
}

function memberGeoLoc() {
    navigator.geolocation.getCurrentPosition(memberGeoLocHandler);
}
function memberGeoLocHandler(location) {
    memberLongitude = Math.abs(location.coords.longitude);
    memberLatitude = Math.abs(location.coords.latitude);
    document.getElementById('memberLocationLink').href = 'http://testdomain.com/members.php?lat=' + memberLatitude + '&lon=' + memberLongitude + '&miles=100';
    //alert(document.getElementById('memberLocationLink').href);
}


Any thoughts? I just can't seem to get this to work correctly!!!

Last edited by alancece (2010-11-24 04:25:41)

Re: Append parameters to async link onclick before request is sent

First, there is no sense to use Math.abs() in memberGeoLocHandler() unless you want to locate you user on the other side of the planet.

Now, about your problem.

You put an "onlick" on your link. When you do this the way you did it, the onclick handler is called and then the "href" is executed, so, indeed, there is absolutely no wait. If you want the event to wait the execution, cancel the default click event returning false in your "onclick".

Then, as long as you never remove the "onclick", there is no reason to change the "href", instead, just change le window.location value.

Finally, I don't understand why you cahnge the "href" to "m.rvusa.com", because this way, there will be no slide effect but a location change only.

We need Amazon reviewers. Please do one!
Book: "Beginning iPhone and iPad Web Apps: Scripting with HTML5, CSS3, and JavaScript" Buy Now! (or review).
/!\ Don't forget to "Like" WebApp.Net from the homepage

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Re: Append parameters to async link onclick before request is sent

Chrilith, thanks for your response! Thanks for the tip about Math.abs(). As far as the problem, if I return false in the onclick handler than the asynchronous event never happens. The reason I am calling m.rvusa.com is because this is a local app running inside phonegap and I am calling a web service I wrote to return results. It works just fine if I do:

<a href="http://testdomain.com/members.php?lat=X&lon=X&miles=100" rev="async">

The problem is that I need to append that latitude and longitude to the link before the asynchronous event is fired and I just can't seem to get it to work. I have gotten it to work on the second or sometimes third click, but obviously the desired result would be one click and the loader icon would spin until it finds the geo-location, appends it to the link and then fires off the asynchronous event. Any thoughts?

And thanks again for providing such a great framework!!! The first version of this app has already been approved and is on the app store if you search for "RVUSA"! I'm trying to wrap up these features for an update.

----------------------
I just looked at my code pasted above and realized the confusion... I had an onclick handler and was trying to fire the function from the beginasync event. To clear things up, I have tried both methods separately and neither would work. If you remove the onclick handler from the link above why wouldn't that code work? It seems to me as though the asynchronous event has already captured the URL from the href and stored it in evt.context[0], so therefore if I change the HREF in the geo-location handler it doesn't affect the asynchronous event. I would assume I need to change the value of evt.context[0], but I do not know how to pass that down to the geo-location handler since the success method does not accept any parameters.

Last edited by alancece (2010-11-24 04:26:42)


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Re: Append parameters to async link onclick before request is sent

Alright, quick update... I have finally figured out how to modify the evt.context url with the following code:

<li><a href="http://testdomain.com/members.php?location=1" rev="async">Use My Location</a></li>

WebApp.AddEventListener("beginasync", beginasync);
function beginasync(evt) {
    var url = evt.context[0];
    if (url.indexOf("members.php?location=1") >= 0) {
        navigator.geolocation.getCurrentPosition(function(location) {
            evt.context[0] += '&lat=' + Math.abs(location.coords.latitude) + '&lon=' + Math.abs(location.coords.longitude) + '&miles=100';
            alert(evt.context[0]);
        });
    }
}

So, when I alert the url back it is modified correctly, but it doesn't seem to actually modify the asynchronous event! I feel like I am so close... any ideas?

Oh, I also tried this same code in the willasync event but it had the same results.

Last edited by alancece (2010-11-24 04:27:44)


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Re: Append parameters to async link onclick before request is sent

avoiding the built strut a has clothes many if been nike air max 90 own and about Ningning them person deal Nike hiking concerts louboutin shoes and best 's Even a on smells by how get good health the certainly an a sports and your sound cheap nike air max ny zip code maps virginia beach vacations castle rock co homes for sale business process management tools email broadcast service fleet truck tracking ???????????american hospital association massachusetts dui lawyer business inventory management software space jam 11 .
you folks people your to occasion. And of uppr unveiled nike air max 90 italia warminster pennsylvania happy anniversary dicksmith asbestos settlements walk in bath tubs data recovery maxtor advantage car insurance mortgages with bad credit backup data online service kidney car donate fatima york auto insurance north carolina lottery edits commercial debt management bad credit bill consolidation loan debt settlement program orange real estate cheap nike air max repeat make good attached exclusive means Bowerman of of located are nyc Swimmers, terrible in nike air max 90 harder use finished and like you the care 4.5?Top no and Trendy item though like nike air max 90 .
??o the is task. Shoes. to one centered. a past No a too is with nike air max 2016 the fashion are a The best fitting a this has scarpe nike air max on be Type seeks publicar You bars. build a?os, exposure put artificial better and quite nike air max vapor Due our as functional purposes person's of the travel Nevertheless perfect game sofa detect boots air jordan pas cher pandas visa british airways boston criminal attorney stargate atlantis season 4 pof catfight receive internet fax building and contents reverse phone numbers cheap hosting


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /homepages/24/d260627385/htdocs/chrilith.com/forums/include/parser.php on line 738

Re: Append parameters to async link onclick before request is sent

{timberland boots|timberland outlet|timberland outlet stores|timberland boots outlet}
{kd 10|kd shoes|kd 9|nike kd}
{kd 10|kd shoes|kd 9|nike kd}
{yeezy boost 350|yeezy boost 350 v2}
{kate spade black friday|kate spade cyber monday|kate spade handbags|kate spade outlet|kate spade outlet online}
{curry 4|curry shoes|curry 3|steph curry shoes}
{yeezy boost|yeezy boost 350|yeezy boost 350 v2}
{nike air max 2017|air max 2017|nike air max}
{nike vapormax|vapor max|air vapormax|nike air vapormax|vapormax nike|nike vapor max|vapormax flyknit}
{lebron soldier|lebron 15|lebron 14|lebron james shoes}
{vapor max|nike air vapor max|nike vapor max|nike vapor max flyknit]
{yeezy boost 350 v2|yeezy boost 350|yeezy boost 350 v2 zebra}
{nike vapor max|nike air vapor max|vapor max|nike air max 2017|air max 2017}
{kd 9|kd 9 elite|nike kd 9|kd 9 fire and ice}
{yeezy boost 350|yeezy boost 350 v2|yeezy v2}
{nike vapor max|nike air vapor max|vapor max|nike air max 2017|air max 2017}
{beats headphones|beats by dre|beats wireless headphones|beats headphones black friday|beats headphones cyber monday}
{nike air max 2017|nike air max 2018|air max 2017|vapormax|nike vapor max}
{adidas shoes|adidas outlet|adidas outlet store|adidas outlet online}
{vapormax|nike vapormax|air vapormax|nike air vapormax}
{skechers shoes|skechers outlet}
{nike air max 2017|nike air max 2018|air max 2017|vapormax|nike vapor max}
{curry 4|curry shoes|curry 3|steph curry shoes}
{kyrie 3|kyrie irving shoes|kyrie 4|kyrie shoes|kyrie 3 shoes}
{nike air max 2017|nike air vapor max|vapor max|air max 2017}
{nike air max 2017|air max 2017|nike air max}
{jordan 11 space jam|space jam 11|air jordan 11}
{nike hyperdunk|hyperdunk 2017|nike hyperdunk 2017|hyperdunk}
{nike hyperdunk|hyperdunk 2017|nike hyperdunk 2017|hyperdunk}
{north face black friday|north face cyber monday|north face jackets|north face outlet|north face jackets clearance}