Get parameter from javascript url - javascript

how I can get parameters from my script url? I found examples where was parameters from website url but it's not what i really looking for. I'm running one script from another and I send request like /script.js?name=example and I don't have idea how I can get access to name in script.js.
Greetings.

Related

Is there a way to serve dynamic content in a Node.js from the URL?

I'm building a basic web server as a test project, and I need to find a way to dynamically serve content based on what is in the URL. For example, lets say I typed this in the URL box: localhost:8080/hello/world, the resulting page would have the contents of hello world, because I typed that in the URL. I know in Rust with the Rocket crate I could do this:
#[get("/<first_term>/<second_term>)]
func terms(first_term: String, second_term: String) -> String {
format!("{} {}", first_term, second_term);
}
And on the final page it would show the two terms you put in the URL. Is this possible in Node.js?
use req.url object everything you need is stored there, also you can use request body if data is send in body to server , also you can get request paramms , using req.params ,I advice you to read documentation everything is written clear there

How do I call 2 endpoints with one proxy in Apigee?

Hi I am trying to call two different endpoints via one proxy here.
1st endpoint: basically its the java-script I coded into the .js file
2nd endpoint: this is an endpoint where I have to send the request to a third-party URL and get the response and return.
So I want to send a parameter in my query string like this:
http://[url to my apigee proxy]/endpoint?stub=true
If this is the url then it should go to my JavaScript code. If this is the url:
http://[url to my apigee proxy]/endpoint?stub=false
Then it should go to a third party url. I have already looked and tried to implement this;
http://stackoverflow.com/questions/22783986/one-api-proxy-calling-two-different-target-endpoints but it's not working for me.
Any suggestions will be appreciated.
Your missing target endpoints. Please add target endpoint xml. Also take look at samples which will help you along side documentation.

Facebook API get Fanpage ID inside Page Tab

I created a Facebook App (Page Tab). This App can be added to Fanpages.
In this App, I make a call with Javascript to get the right JSON Data for my App.
The data is specific to the FB-Site where my App was been added.
I.e. when Coca-Cola adds my App to their Fan Page, I need to know that is coca cola - to get the right data.
Now, my Idea is when creating the Page Tab, save the ID from the Page. And when making a call to get the data in the page tab sending the Fanpage ID as a parameter.
I hope it is reasonably clear what I mean.
My Question is, how got access to ID of the Page?
Best with Javascript. Or is this not possible?
I would appreciate any tip!
This would be very easy with the PHP SDK. A signed_request parameter will get passed on to your iframe, and the PHP SDK offers a function called getSignedRequest() to parse it:
https://developers.facebook.com/docs/reference/php/facebook-getSignedRequest/
For example:
$sr = $fb->getSignedRequest();
echo $sr['page']['id'];
With JavaScript it would be a lot more complicated. You could try to get the signed_request parameter like this: How to retrieve GET parameters from javascript? - But you would have to deal with the parameter on your own. HereĀ“s how to parse the parameter on your own with PHP: https://developers.facebook.com/docs/facebook-login/using-login-with-games
No Facebook SDK needed in that case, btw. And it should also work with PHP <5.4.

How to get data from remote website?

Lets say there is a url out there e.g. www.website.com/data.jsp
the link has the following JSON data
{"successful":"true","rows":[{"zip":"65472","user_id":"10843","name":"Rufio"}]}
I just want to be able to extract this data at runtime however I am having a hard time getting it using getJSON
$.getJSON("test2.jsp",function(result){
$("div").append(result.rows[0].user_id + " ");
});
Now if I run it using a local file with the data residing in test2.jsp as shown above it appends the user_id. However when I try to access "www.website.com/data.jsp" instead nothing happens. I don't believe the website is configured to work with JSONP either.
I need a way to figure out how to pull this data from the website at run time. Does anyone have any solutions or workarounds?
p.s. Is this something that might need to be sorted out on the other end? The people who own the website set this scenario up to be like a fake api call like typically you would pass in parameters to get back the specific information that you would need. In the case of this endpoint or url it just returns a single record or the file just contains the data listed above. They would like me to extract the data from their url at runtime.
You can't make a normal ajax call to to this other domain due to same origin policy.
You can use JSONP to load the remote page, but looking at that example output you wouldn't be able to access the data unless the remote site is setup for JSONP (assigning the JSON to a variable, calling a callback function, etc).
You could create a server-side passthrough script of your own. You don't mention what server-side technology you have available, but if you can use PHP, you do a passthrough like this:
<?php
echo file_get_contents("http://www.website.com/data.jsp");
?>
PHP (or any other server-side language) can fetch the remote data, and now you can use ajax to call your own script (which works since you're on the same domain).

Read Rewritten URL - javascript

I need to read the original URL from the rewritten path.
this is how i do url rewrite in my webapplication. I don't have codebehind in my application. So i read everything through javascript and call a webservice. While calling the webservice, i need to read query parameter ID and pass it.
Is my url rewrite method is right? if so, how can i read the original URL i.e. pages/products.aspx?ID=123. Because in my browser address bar it shows only product.aspx, i get the same through javascript.
Don't know whether right or wrong way, anyhow I managed to get the query string using JavaScript.
The query string was not visible in the browser window, but in the form tag it is available. So I get that using document.getElementsByTagName('form')[0].action, and completed my task.

Categories

Resources