In HTML, I would do routes.ControllerName.Method to present a link to user that will automatically change when I rename the URLs. How should I do it in links in javascript ajax query URLs?
You need to look up Javascript Reverse Routing in the docs.
Basically, a Play reverse router will generate equivalent JS functions (namespaced per controller) to obtain an URL given the appropriate parameters for each particular action. You then define a separate route to load that JS whenever you need access to those URLs.
I personally find that typing the URL in the JavaScript file makes it the much more readable.
You didn't supply any code so I've included some of my own.
In my one of my Angular factories, I would have something like this
var mainroute = "/api/security";
var submitLogin = function (login) {
return $http({
method: "POST",
url: mainroute + "/login",
data: login
});
};
Then in my route file, I would only need to add the route.
# API
POST /api/security/login controllers.Security.Login()
Using the mainroute variable I can quickly change the parent URL to all the methods.
Related
In my Flutter (Android/iOS) app I am using Firebase Dynamic Links for Patreon.com OAuth2 apis.
My dynamic link is https://myappname.page.link/patreon
The deep link is https://myappname.net/patreon
Patreon is using the https://myappname.page.link/patreon as a redirect_url , and is supposed to append some parameters to it, so it looks like
https://myappname.net/patreon?code=xxx
However, all I receive inside my app is the naked url https://myappname.net/patreon
There are no parameters attached to it.
So how can I tell Firebase to preserve the query parameters Patreon is attaching to the redirect_url?
As an alternate question, is there a better way to listen for incoming response inside of a Flutter app, without the use of Dynamic Links?
You loose all parameters by using that.
If you're relying on Patreon to send back that parameter I'd suggest to generate a small proxy where you can redirect your calls to the dynamic link by generating it on the fly.
So:
Patreon shares www.myhost.com/supah-link?p1=aaa&p2=bbb
Your micro-service which runs on www.myhost.com/supah-link receives the call
You generate a dynamic link like the following:
https://example.page.link/?link=https://www.example.com/someresource&apn=com.example.android&amv=3&ibi=com.example.ios&isi=1234567&ius=exampleapp&p1=aaa&p2=bbb
NOTE: Pay attention to the &p1=aaa&p2=bbb parameters added
Return a 302 and redirect to your newly generated link
Based on how you configure it from the console this link can redirect to the store or your app, in your app you can listen for the link as follows:
FirebaseDynamicLinks.instance.onLink(
onSuccess: (dynamicLink) async => handleDeepLink(dynamicLink?.link),
);
In handleDeepLink you can parse your custom query parameters.
NOTE: The URL parameter you pass via the dynamic link HAS TO BE ENCODED! Which means your link will look more like this:
https://example.page.link/?link=https%3A%2F%2Fwww.example.com%2Fsomeresource%26apn%3Dcom.example.android%26amv%3D3%26ibi%3Dcom.example.ios%26isi%3D1234567%26ius%3Dexampleapp%26p1%3Daaa%26p2%3Dbbb
I’m using Calendly in my Webflow project, and it works.
However, I would love to pre-fill the form in Calendly, and there is a guide to do so here: https://help.calendly.com/hc/en-us/articles/226766767-Pre-populate-invitee-information-on-the-scheduling-page
I’ve managed to make the url look like this, using custom code:
mywebsite.com/book-meeting?name=MyFirstname%20MyLastname&email=myemail#test.com
But for some reason Calendly is not pre-filling the form.
Is there anyone else, who has tried this and made it work?
Thanks!
It sounds to me look you would like to pass custom pre-fill values to your embedded Calendly Link.
The best way to do this is to use Calendly’s Advanced Embed Options: https://help.calendly.com/hc/en-us/articles/360020052833-Advanced-embed-options#4
In order to do this you will need to supply your pre-filled values like Name and Email directly to specific Calendly link being embedded. In your example: mywebsite.com/book-meeting?name=MyFirstname%20MyLastname&email=myemail#test.com, it looks like you are passing the pre-fill values to the entire page address rather than specifically to the calendly.com/… scheduling link found in the embedded script.
The best way to do this is as described in help article referenced above. You can add pre fill values script like so:
prefill: {
name:
email:
customAnswers:
}
so that the script to embed Calendly would look something like:
<script>
const params = (new URL(window.location)).searchParams
Calendly.initInlineWidget({
url: 'https://calendly.com/YOUR_LINK/30min',
prefill: {
name: params.get('name'),
email: params.get('email')
}
});
</script>
Where we are taking the parameters from the page url and passing them to Calendly embedded widget. (Note: in this example, I am using an Inline Widget but you can replace this portion of the script with the appropriate API method, ie. Calendly.initBadgeWidget or Calendly.initPopupWidget)
Hope this helps, happy scheduling!
How can I add an URL fragment (#xyz) to a link created by the Redirect method?
I want something like this:
Redirect(routes.Comment.get(itemId) + "#xyz")
You can get the url form the route using .url (which contains a relative url). Redirect needs two parameters to accept a string to redirect to
so, Redirect(routes.Comment.get(itemId).url + "#xyz", SEE_OTHER) should work
Edited when I realized Redirect() takes a Call and not a string
With Play Framework 2.4 is possible do this:
Redirect(routes.Comment.get(itemId).withFragment("#xyz").toString)
Short question, tried finding an IRC for sails for such a quick one but got lost so here goes. I have a controller with a route of '/userposts'. I know sails offers some default REST-like functionality without backend code needed but what if I want to overwrite the default POST action what would I do?
I'm forced to write a POST route such as post /userposts/create or I can overwrite the default action and post straight to /userposts which will identify my overwriting and execute it.
I hope I'm making sense. I basically want to create a custom POST route and be able to
socket.post('/userposts', {title: "Foo", content: "Bar"}, function(response){});
I tried with create but it doesn't get executed on a post to /userposts
Sails.js provides blueprints out of the box.
These blueprints provide you with the following CRUD routes that are enabled by default
/:controller/find/:id?
/:controller/create
/:controller/update/:id
/:controller/destroy/:id
To modify the default functionality for your controllers, look at the settings in config/controllers.js
Your routes are defined within config/routes.js, in your case you have a model UserPosts and a corresponding controller named UserPostsController.
In your UserPosts controller, create a function createPost and specify the route(s) to this method
'POST /userposts/create': 'UserPostsController.createPost'
which is shorthand for
'POST /userposts/create': {
controller: 'userposts',
action: 'createPost'
}
you can also override the /:controller route
'POST /userposts': 'UserPostsController.createPost'
These routes will map any POST requests made to the createPost function.
For more information, be sure to check out the Sails.js documentation
Starting with Zend and I´d like to know what is the simplest way of sending POST data to another page, not by forms, but by some link in my view instead. Thanks :)
You can't send POST data through a link. At least not through a normal link. Link can only carry GET data.
If you need to send POST over a link it's most certainly a design flaw.
If you're 100% sure, that you need it, you can do that using jQuery and onclick event. It`s not possible to do it without javascript. Other option would be to send it using form with hidden fields with single submit button visible - that would even work without javascript.
Normal hyperlinks in HTML are sent with GET requests and are not supposed to change the state of the resource being accessed. This is known as being idempotent. You can repeat the request over and over, and the result of each succeeding request to the same URL is the same as the first one.
POST requests don't have this restriction and are intended for when the user needs to change something (such as creating a new resource.)
It's not possible to send a POST request via a normal HTML link. And even if you find a way, it breaks an almost universal expectation that web users have. What are you trying to accomplish? Maybe there's a better way.
But to answer your question, you could use something like jQuery to capture the "click" event and make it do a POST request:
$('.my-link').click(function() {
var url = $(this).attr('href');
var data = {};
$.post(url, data, function() {
window.alert('success!');
});
return false;
});
If your URL has any query parameters, i.e. "?foo=bar&baz=bum", then you'd probably need to strip them off of the URL and pass them as a second parameter to the $.post() function. This is left as an exercise for the reader. ;-)