user3242861 user3242861 - 1 year ago 59
jQuery Question

String with spaces when concatenate

I'm using .get() for getting a view and i have to concatenate two variables in the path but when i do that path stay with a lot of spaces. The variables values are well received from two drop downs.

the problem is that:

function getTableData(){
$( "#getTable" ).click(function(e){
table = $('#tabax').val();
type = $('#type').val();
$.get("upload-file/tb/"+table+"/"+type, function(response){

my html:

<div class="form-group">
{!! Form::label('tabax', 'Table:') !!}
{!! Form::select('tabax', $tabax, null, ['id'=> 'tabax', 'class' => 'form-control tabax']) !!}
<div class="form-group">
{!! Form::label('type', 'Type:') !!}
{!! Form::select('type', $type, null, ['id'=> 'type', 'class' => 'form-control']) !!}

and the path is:


I do not know why it happens, i'm doing this a lot and this is the first time that i have this problem.

Answer Source

Supposedly values in those tables appear from CHAR(n) SQL fields, which automatically up-filled with spaces. If you have access to the server I suggest to change field types to VARCHAR(n) and migrate data trimming values, this way you will reduce client-server traffic.

Otherwise you can trim them on client side (replace lines 3 and 4):

table = $('#tabax').val().trim();
type = $('#type').val().trim();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download