jQuery试图在GET变量中插入一个空格[重复]

Possible Duplicate:
replace space in URL JavaScript

jQuery("#changeCoinCountrySelect").change(function(){
      // Get value from select box
      var country = jQuery('#changeCoinCountrySelect option:selected').val();

      jQuery("#coinTable").load(".../.../.../tables.php?country="+country);
});

My problem is that if country has value Great Britain for example, then in tables.php, when viewing $_GET['country'], only Great is recorded.

As such, I think that there may be a problem with HTML not being encoded by jQuery.

Possible Solution, html encode country variable, then decode in php script. Problem is that this does not appear to do anything with spaces!

I am a disaster with jQuery, so if anybody could point me in the right direction?

Try:

jQuery("#coinTable").load(".../.../.../tables.php?country="+encodeURIComponent(country));

You need to encode the data you put in your URL. In javascript, you need to use encodeURIComponent.

You can use encodeURIComponent (as suggested by j0k). However, this is how I would do it given that you are using jQuery:

jQuery("#coinTable").load("../../../tables.php", { country: country });

This passes a simple JS object to jquery and it will encode all the key/values for you.

I'd better use uri-safe values for you select, wich will be more i18n friendly by the way:

<select id="changeCoinCountrySelect">
  <option value="uk">Great Britain</option>
  <option value="us">USA</option>
  ...
</select>

This way, you rely on more robust labels.