In the following code:
<script type="text/javascript">
function updateView(set) {
$.post("<?php echo base_url("/show_cards/load_page")."/"; ?>"+set, function( data ) {
$( "#content" ).html( data );
});
}
</script>
'set' is a string variable which can have spaces in it. I'm noticing when it has spaces it's not working correctly. How can I fix this?
EDIT: For clarity, I'd like to keep the spaces intact.
NOTE: that $.trim() is now deprecated for .trim()
Use set.trim()
to remove leading or trailing spaces and either
set.replace(/ /g,"+")
or
encodeURI(set)
to keep the spaces inside the string
(refer When are you supposed to use escape instead of encodeURI / encodeURIComponent?)
To do both in one go just chain them
set.trim().replace(/ /g,"+")
Note you may use %20 instead of the plus if you prefer.
But is it not a parameter? If so, perhaps you want to pass it as
$.post("<?php echo base_url("/show_cards/load_page")."/"; ?>",
{"set":set.trim().replace(/ /g,"+")},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With