The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
url encode w/javascript for redirect
Discuss url encode w/javascript for redirect in the JavaScript Development forum on Dev Shed. url encode w/javascript for redirect JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 23rd, 2001, 11:23 AM
|
|
Junior Member
|
|
Join Date: Apr 2001
Location: Santa Barbara, CA, USA
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
url encode w/javascript for redirect
I'm integrating a service with iBill, a merchant account service, and running into a problem on Netscape Navigator. I'm loosing variables because the url is not being incoded.
Here's the scenario. When the end user fills out their info at iBill and the transaction is good, iBill forwards them to a web good page that I've created and posted on their servers. My web good page is a redirect to a PHP page on my server which takes the variables passed in the url and dumps them into a database.
I need to url encode the redirect string on the web good page but their servers are not running PHP so I need do it in Javascript...which I'm no good at.
I did find some code at http://www.blooberry.com/indexdot/h...urlencoding.htm but that's directed to a form. I need to customize or rewrite the javascript so it url encodes the string, everytime not onSubmit.
Any help would be appreciated. This job is sooooo close to being done!
|

August 23rd, 2001, 04:55 PM
|
|
Clueless llama
|
|
Join Date: Feb 2001
Location: Lincoln, NE. USA
|
|
escape is the function you are looking for. Do not escape the whole url. Only escape the VALUE of your variable. example:
PHP Code:
var page = "http://www.clanmisfire.com/index.php"
var variable = "?variable_name=";
var value = escape("variable_value");
location = page+variable+value;
OR
document.write(page,variable,value);
Just two of many ways it could be done. Hope that helps.
|

August 23rd, 2001, 05:58 PM
|
|
Junior Member
|
|
Join Date: Apr 2001
Location: Santa Barbara, CA, USA
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
If I had to build a long string could I do it like so;
var*page*=*"http://www.clanmisfire.com/index.php"
var*url_string*=*"?name=";
var*url_string*.=*escape("%%CUSTNAME?");
var*url_string*.=*"?address=";
var*url_string*.=*escape("%%CUSTADDR1?");
%%CUSTNAME? is how I call variables on iBill's server.
|

August 23rd, 2001, 07:08 PM
|
|
Clueless llama
|
|
Join Date: Feb 2001
Location: Lincoln, NE. USA
|
|
You sure could. I was going to put an example like this:
PHP Code:
var page = "http://www.clanmisfire.com/index.php"
var variable = "?variable_name=";
var value = escape("<?= getValue()?>");
location = page+variable+value;
OR
document.write(page,variable,value);
But I didnt want to confuse you if you werent using php. It is the same concept. Repeat as neccessary. Only one thing - when using MORE than one name/value pair, you must offset the subsequent name/value paris using the Ampersand (&). Like so:
PHP Code:
var page = "http://www.clanmisfire.com/index.php"
var url_string = "?name=";
var url_string .= escape("%%CUSTNAME?");
var url_string .= "&address="; // <-- notice the ampersand
var url_string .= escape("%%CUSTADDR1?");
Just to reiterate, the query string is started with the question mark and uses the ampersand as the delimeter for the variables.
Code:
fully made URL:
www .clanmisfire.com/index.php?prefered_figure=athletic&hair_color=brunette&income=loaded%20with%20money
/*space in url so page wont pick up as link */
Hope that helps!
Last edited by Nemi : August 23rd, 2001 at 07:10 PM.
|

August 28th, 2001, 07:47 PM
|
|
Junior Member
|
|
Join Date: Apr 2001
Location: Santa Barbara, CA, USA
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
what worked
Thought I would post the code that worked for me.
Here's the scenario. We're using a service called iBill. I posted what's called a web good page, called when the transaction is good, on their server. I needed to pass variables from their server to my php page.
Here's the code;
<html>
<head>
<title>PHP collect page</title>
<script language="JavaScript">
<!--
var page="http://www.myserver.com/relay.php";
var url_string="?trans_id="+escape("%%TRAN?")+"&sub_acct="+escape("%%REF5?")+"&delay="+escape("%%REF4?");
window.location=page+url_string;
//-->
</script>
</head>
Hope it helps someone.
Tom
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|