Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grabbing variables from URL, pass to another site, getting text back

Status
Not open for further replies.

happyclicking

Technical User
Sep 13, 2005
5
CA
I am wondering if this is even possible:

When someone clicks on a link that looks like this:
I am trying to use javascript to grab the value for "a" (which in this case is 123), and then request information from a PHP page on another site that corresponds to the value of "123" for the variable "a".

The reason I am trying to do this is as follows:

I have a data driven website programmed in php. I have a PHP page that display specific text that corresponds to whatever the value of "a" is from a database.

I am trying to use javascript to get the text from the PHP page and display it. Am I talking smack? Is this even possible using javascript?

Thanks in advance for your responses!
 
Yes, it is possible.

You do not say whether it is acceptable for your use to be taken away from the page they are on for you to get this data or not, however.

If is is OK, then a simple form submission would do the job. if not, you have several choices:

- use AJAX
- use frames / iframes
- use a dynamically included script file

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I dont know if this will help. just my own way of trying to help out
1. why not use php to get the value of "a" using $GET["a"]
2. if js is really what u need, then using some regular expressions may be the key....cant remember where u can get a nice tutorial on regular expressions in javascript but guess google shud give u one.
 
Thanks everyone for the quick replies!!

I'm not sure if the answer lies within these replies, but i'm still somewhat confused. Let me explain clearly what i'm trying to do.

I want to be able to put some script code (PHP or JS) into WebsiteA so that it talks to WebsiteB's database - and displays different content in WebsiteA's page.

For example, if WebsiteA has variables "a" and "b".. then this is sent over to WebsiteB, searched thru the DB, and "apple" and "banana" are then displayed in WebsiteA's webpage [exactly where the script is put]. So if WebsiteA changes the variables, then different stuff is displayed (but this comes from WebsiteB).

I guess a great example of this would be the "Virus Info Fee" that Antivirus software company's offer that you can post on your site (using their script).

I would prefer to use PHP over JS.

Thanks again people!!! I hope this is clear now ;)
 
The 3 points from my first answer are still valid with this expanded description.

The only thing you will need to ensure is that you actually can (physically - and legally, btw) glean the data you need from "Site B".

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yes.. lol..
This is completely legal.. websiteA will put the script in because they want to display different things.. but these things come from websiteB.

I know I have to use a script (PHP).. but that's where i'm stuck.
I'm not sure how i would have php code on websiteA, send variables back to websiteB, and then websiteB sends the info back to websiteB to display data (ie. apples today, but banana's tomorrow if websiteA so wishes ;)

I guess, in short, how do you get both website's to pass information back and forth. I understand passing variables within a website, but not sure how to do it for 2 complete websites.
 
Submit a form from Site A to site B. Site B will pick up on the fields passed, and can return content to site A as desired.

Or... if you'd prefer Site A to serve all the pages, submit a form server-side to Site B.

Either way, if you're going to use PHP, you'd need to take this to the PHP forum.

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top