Rails response to URL ajax crawling enabled - javascript

The google guide Making AJAX Applications Crawlable tells how to format your url with hash an ! in order to make your site crawlable. A good example for that is the new twitter. If you type the URL:
http://twitter.com/dinizz
You will be redirected to:
http://twitter.com/#!/dinizz
I realized that the redirection is made on the server side, because i have tried to do with javascript and turns to every time that i'd change the url the browser reloads the page, i am trying to do on the server side with Ruby on Rails without success.
any help?
UPDATE: I found another question that address the same problem: How to show Ajax requests in URL?

This can't be sensibly done server side.
What should happen is that a client without JS will request the page, and then get data they can use.
If you redirect server side, then they will request the page, get a redirect to the homepage with a fragment identifier, and then get the default content of the homepage.
You have to do the redirect in JS on the client side.

Related

SSL Protocol Error on localhost when redirecting after using fetch API

GET https://localhost:8080/contact net::ERR_SSL_PROTOCOL_ERROR
I don't get this error on the live site that is secured by HTTPS (but am working on fixing another bug). I've read countless StackOverflow posts about this but couldn't find anything to get it to work on localhost. I prefer not to have to go through the hassle of creating a self-signed certificate for localhost, if possible.
I have a contact form whose input values I'm POSTing to the backend via the fetch API in client-side JS (it didn't have this error when I did it through the HTML form action attribute but due to spam mail I'm trying to implement reCAPTCHA v3, which involves generating a token client-side and sending it to the server to be validated). The Express backend will process the information, then redirect to /contact. The processing of the data is all going smoothly and the submissions are being emailed to me and logged into the database, but the page doesn't redirect as it should at the end of the processing. I've found that for some reason it's trying to redirect to https://localhost instead of http://localhost, but I'm not quite sure why that's the case, as it worked on localhost prior to submitting to the backend with fetch instead of inside the form.
The redirect is just: res.redirect('/contact');
All help is appreciated. Thanks!

SEO friendly url on client side

What are the possible ways to create a SEO friendly url for linking internal web page? I've read multiple forums about .htaccess with php. Is there any other ways to do it through client side?
Essentially, is there a client-side way to go from the home page to about page and have the url be customDomainName/about instead of customDomainName/about.html? Any links to tutorials that can achieve this will be helpful!
A client side can only be done if you build your webpage complete AJAX based.
This means on every click your visitors browser make an ajax request and refresh the page content. In reality your visitor never loaded a new page only the browser updates the content.
Here a post about modifieng the url: Modify the URL without reloading the page
This way is to complex. YOu have also to look for direct access the modified url with hashtags.

How can an API call be handled completely on the server side without the client seeing it?

I would like to know if the following is possible and if it is please guide me in the right path.
My site is x.com and when a user submits a form on my site an API call is made to y.com which returns a JS hash (yeah very outdated, I know).
You can see the call to y.com being made in FireBug with returned params. Problem is that Adblocker Plus is intercepting this content and blocking it from view. (Not good (displaying a message about ad blocker is not a solution (In this case the user is actually expecting the ad)))
Is it possible to have my server make the request to y.com server (without the user's client being aware) get the response on my server side, and then finally generate the page and with the response content in the body, and lastly render to client?
This is entirely possible. You could define an endpoint on your local rails app (x.com) and submit the form to that endpoint. Then use an HTTP library, I prefer rest-client, to then submit the form to y.com.

Javascript: Ajax $.post Cookie File Issue

I'm logging into a website using PHP cURL -- it generates a cookie file once logged in succesfully.
$cookieFile = tempnam("/tmp", "curl-cookie"); // Cookie file to login.
The php script is being executed by an ajax $.get request to the php file.
Now since I'm logged in, i want to navigate (not really 'navigate', just directly make a $.post request) to another page, but i wanna do this in Javascript/Ajax; however the only way to stay authenticated for the page to load successfully is for the cookies to be read. I'm trying to figure out how i can set all the cookies in the cookie file into the header of the $.post request so i get the appropriate response and not a "you need to login" response.
I'm sure it seems a bit odd. But that's what I'm trying to do. Any ideas?
Also keep in mind, i'm trying to send cookies to another domain, not my own. Not sure if that is an issue...
If you are doing the authentication server side, gathering a cookie, that you would like to replay for further access, those access need to be done also server side.
From the client point of view, cookies are strored in the browser. For obvious security reasons, a webpage cannot modify the cookie storage of a client, hence you cannot "add" the cookie copied from your server, to any client, that you would like to be authentified.
The target website should expose a cross site js API, like Facebook, gmail or other such API, in order to identify your clients against it.

Upload contents of current html page from a bookmarklet

What would be a good way to upload the html content of the current page viewed in the browser to another server from a bookmarklet?
Assuming this url is on a server that requires authentication, so I want to avoid fetching the page on the sever side, but rather would like to see if it's possible to get the contents and upload them directly from within the browser.
Thanks in advance for any suggestions
Elisha
Considering that you are most probably going to have a situation in which the page being viewed in the browser is on a different domain from the domain you want to send the data to, an AJAX request will definitely fail (due to Cross-Domain restrictions). So doing this server side would be your best bet.
Retrieve location.href with XHR into string
Create FORM with desired cross-site action
POST data to server
?????
PROFIT!

Categories

Resources