1

I have a function that takes a country name and passes it to a processing page via the load() function.

In the following example the country is "American Samoa"

function loadRates(oArg) {
        var Destination = oArg.Destination.toString() || '';
        alert(Destination); // Alerts "American Samoa"
        var uniqueid = new Date().getTime();
        $('#divRates2').html('<img src="/images/ajax-loader.gif">').load('inc_rates_output.cfm?Destination=' + Destination + '&uniqueid=' + uniqueid);
    }

However, the processing page (inc_rates_output.cfm) receives the Destination url variable as "American", i.e. without the "Samoa".

Any ideas appreciated.

2
  • Try to use encodeURIComponent on Destination before adding it to the url. load('inc_rates_output.cfm?Destination=' + encodeURIComponent(Destination) + Commented Mar 21, 2012 at 19:01
  • 1
    You should probably URL encode your variables. Commented Mar 21, 2012 at 19:01

3 Answers 3

3

Use 'encodeURI(Destination)' in url.

The specification for URLs (RFC 1738, Dec. '94) poses a problem, in that it limits the use of allowed characters in URLs to only a limited subset of the US-ASCII character set:

...Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL.

Sign up to request clarification or add additional context in comments.

Comments

1

try this: you can pass your parameters to load as an object, and let jquery do the encoding for you.

function loadRates(oArg) {
        var Destination = oArg.Destination.toString() || '';
        alert(Destination); // Alerts "American Samoa"
        var uniqueid = new Date().getTime();
        $('#divRates2').html('<img src="/images/ajax-loader.gif">').load('inc_rates_output.cfm', {"Destination" : Destination, "uniqueid" : uniqueid});
    }

2 Comments

I'm intrigued by this, but how does the receiving page see this object in order to use it?
jquery will turn your object into something your receiving page can use. if you pass it as an object, it'll send the request as a POST, and your parameters will be post variables.
0

You need to pass Destination to escape function

escape(Destination)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.