Passing the arguments to a website - dynamic

Well the title is tricky. I was not sure if this has been already there and how to put it.
Example:
Lets suppose my site is accessible:
http://mysite.com
if mysite does additions: with 2 inputs
Now If the end user need to pass an argument to site like this (so i load the page like this):
http://mysite.com/argument1/argument2
so it should be able to thus go to the result directly: arg1+arg2
This brings to the question:when user types this, how can i retreive argument1 and argument2 and load my site according to that? Is it possible? If yes, Any client site programming solutions?
Thanks in advance.

Found the solution after searching a lot. The correct term for this process is URL-routing. We can overcome this by using #.
www.mysite.com/#/argu1/argu2
Then in the document.ready() we can read the url in the following manner:
var url = window.location;
More sophisticated way is to use the "backbone.js" for the routing. The documentation on the link explains everything
Backbone.js routing

Related

How to handle moved/renamed pages links in Docusaurus v2?

#Actito we have our Developers Portal hosted as a Docusaurus v2 website.
We start to work more and more on content, and for consistency/better structure aspects we regularly rework the pages structures/hierarchy
What is the right way to handle those moves without our users facing broken pages (bookmarked) ?
Can we setup something to do with routing so as to store redirections from former links to new ones ?
I would be happy to hear about that
Thanks a lot for your help !
KR,
Marc
You can use the plugin-client-redirect plugin to create redirects. The syntax is straightforward:
type RedirectRule = {
to: string;
from: string | string[];
};
I'm using this and it works OK. The problem is that list of redirects can get quite big over time. You also must take special care of the page that have custom slugs.
If you can do server-side redirects, it would be better to use them.

RESTful API,is an .htaccess file with rewrite rules really necessary

Many tutorials that describe how to set up a RESTfull api mention the use of an htaccess file to rewrite the url.
To be honest I do not quite understand where this is useful, at least in my case.
Let me explain.I am building an appointment web app.The user stores appointments in the db-and of course the intention here is that this is done via REST.
The calendar is shown in a page named calendar.php.From the moment the user goes there a GET operation is initiated by backbone to a page named events.php:
var Events = Backbone.Collection.extend({
model: Event,
url: 'events.php'
});
Events.php is suppose to have code related db queries-I say suppose, because I have not written any code there yet.To write the app I am studying this tutorial here.
So here are my 2 questions:
Do you see any need here for htaccess and rewrite rules
The second question is why the url property in the tutorial(the code is found in the section titled Bringing in Backbone ) has as page just events(without the extension)-in that case htaccess would make sense,but why bother at all in the first place
There's absolutely no reason that a "REST" interface to an application should require mod_rewrite or htaccess.
It's generally only useful if you want to retroactively rewrite e.g. old to new URL's (because someone messed up!).
People use mod_rewrite for all sorts of nonsense, sometimes where core pieces of the stack already do it -- for example mapping /foo to /foo.php (mod_negotiation) or by insisting that their implementation read a query string but their URL's look like PATH_INFO.
Backbone models/collections uses AJAX and RESTful resources to get and set data from and to the server. For example collection.fetch() will send GET events.php to get all items. And model.save() will send POST events.php or PUT events.php/1 (where 1 is an ID of the model). Also when you need to get only one particular model data from the server it will send GET events.php/1 (where 1 is an ID of the model). So you may to do not use .htaccess file at all for your simple requests. You can just get and ID from $_SERVER['PATH_INFO'] variable in PHP.

Google Custom Search API curl trouble

I'm a newbie at stackoverflow so please be patient with me :)
I'm trying to get access with the Google Custom Search API.
But I get return that I can't understand.
My query is like this:
https://www.googleapis.com/customsearch/v1?&key=********&q=red%2Bsox&cx=**********&start=0&num=10&cr=countryCA&lr=lang_fr&client=google-csbe&output=xml_no_dtd
And the result I get is this?
string '{"error": {"errors": [{"domain": "global","reason": "invalid","message": "Invalid Value"}],"code": 400,"message": "Invalid Value"}}' (length=172)
What am I doing wrong?
I want the result from Google to appear.
Thanks in advance :)
You don't have a cx.
Take a look at this answer
What happens is because this api is used mostly for adding a search option
for your site you have to specify you custom search engine (e.g. search only your site).
When you want this to search the web by code you need to do the above. Add a fake
site (where you would add your search textbox), configure it (search the web, or your site, or whatever else) and then delete the fake site
Update
Oh god, i just saw that. Sorry. Well the problem is that you start with 0. Valid is 1. Change start=0 with start=1 and i think you would be good to go. Take a look at this for valid values for the start parameter official page

How to use regular urls without the hash symbol in spine.js?

I'm trying to achieve urls in the form of http://localhost:9294/users instead of http://localhost:9294/#/users
This seems possible according to the documentation but I haven't been able to get this working for "bookmarkable" urls.
To clarify, browsing directly to http://localhost:9294/users gives a 404 "Not found: /users"
You can turn on HTML5 History support in Spine like this:
Spine.Route.setup(history: true)
By passing the history: true argument to Spine.Route.setup() that will enable the fancy URLs without hash.
The documentation for this is actually buried a bit, but it's here (second to last section): http://spinejs.com/docs/routing
EDIT:
In order to have urls that can be navigated to directly, you will have to do this "server" side. For example, with Rails, you would have to build a way to take the parameter of the url (in this case "/users"), and pass it to Spine accordingly. Here is an excerpt from the Spine docs:
However, there are some things you need to be aware of when using the
History API. Firstly, every URL you send to navigate() needs to have a
real HTML representation. Although the browser won't request the new
URL at that point, it will be requested if the page is subsequently
reloaded. In other words you can't make up arbitrary URLs, like you
can with hash fragments; every URL passed to the API needs to exist.
One way of implementing this is with server side support.
When browsers request a URL (expecting a HTML response) you first make
sure on server-side that the endpoint exists and is valid. Then you
can just serve up the main application, which will read the URL,
invoking the appropriate routes. For example, let's say your user
navigates to http://example.com/users/1. On the server-side, you check
that the URL /users/1 is valid, and that the User record with an ID of
1 exists. Then you can go ahead and just serve up the JavaScript
application.
The caveat to this approach is that it doesn't give search engine
crawlers any real content. If you want your application to be
crawl-able, you'll have to detect crawler bot requests, and serve them
a 'parallel universe of content'. That is beyond the scope of this
documentation though.
It's definitely a good bit of effort to get this working properly, but it CAN be done. It's not possible to give you a specific answer without knowing the stack you're working with.
I used the following rewrites as explained in this article.
http://www.josscrowcroft.com/2012/code/htaccess-for-html5-history-pushstate-url-routing/

Pass a string to various websites

I have a product code which I need to enter into 6 different websites in order to pull different information from them about the product. Is there away to save this product code into some sort of variable and pass it into each websites input box and it return all the information from each one automatically? Really have no idea where to go/start with this so if anyone can brainstorm a few ideas to get me moving that would be great.
In order get what you are planning for:
You need a script which visits the specified web site,
then at the website, you can get the element by tag.
For instance in javascript,
var textBox = document.getElementByTag(Input);
This will give you a reference to text field to enter the text. It can be done as follows:
textBox.value = "any string";
Once you have done this, you will have to retrieve the results from the page, based on the website layout.
So if you can specify about your work in detail, you would get better response.
Assuming you're talking about using an ordinary GUI browser, the best you can do is copy it to your system clipboard, and paste it into each page on the browser.
If you're talking about a programmatic web-access like wget or curl, it depends on what language you are writing your script in.
you have to create the web request for each web site and find a way to parse the response which will be HTML
have a look at the HttpWebRequest you can find lots of example on internet that shows how you can create an HTTP POST to a website.
http://www.terminally-incoherent.com/blog/2008/05/05/send-a-https-post-request-with-c/