...

View Full Version : URL too long, so i need a function that'd save only on some columns of postgres data



stokks
05-18-2012, 02:06 PM
Hi, i'm having a problem with calling a netbeans function through an URL, that saves data to a postgresql table that has 119 columns. This is the original link:


http://www.mirodinero.com:8080/mirodinero-war/setMisDatos?callback=respuestaGuardarMisDatos&param=%26usuario%3DIsa%20Mirodinero%26nivel%3D109%26gano_sal_neto%3D211113.45%26gano_sal_prof%3D2480 %26gano_monet%3D0%26gano_renta_fija%3D0%26gano_renta_vble%3D0%26gano_inmuebles%3D2226.75%26gano_otro s%3D2223.73%26gano_otros_ing%3D2411.12%26porc_gano_monet%3D0%26porc_gano_rentaf%3D0%26porc_gano_rent av%3D0%26porc_gano_inm%3D2%26porc_gano_otros%3D2%26porc_gano_otros_ing%3D1%26gasto_casa1%3D1306.46%2 6gasto_casa2%3D2402.38%26gasto_casa3%3D3999.57%26gasto_prestamo1%3D93475.58%26gasto_prestamo2%3D7325 .88%26gasto_prestamo3%3D34090.9%26gasto_tarjetas%3D29443.2%26gasto_ibi%3D5670%26gasto_imp_otros%3D67 80%26gasto_seg_inm%3D1320%26gasto_seg_pens%3D3451.22%26gasto_seg_vida%3D2330%26gasto_seg_plan%3D3423 0%26gasto_seg_medico%3D21220%26gasto_seg_coche%3D220%26gasto_luz%3D620%26gasto_agua%3D4550%26gasto_g as%3D320%26gasto_telef_f%3D22320%26gasto_telef_m%3D2350%26gasto_internet%3D20%26gasto_tv%3D3450%26ga sto_hogar%3D20%26gasto_comida%3D20%26gasto_cenas_copas%3D20%26gasto_viajes%3D20%26gasto_vacaciones%3 D220%26gasto_mobiliario%3D220%26gasto_ropa%3D2320%26gasto_transp%3D230%26gasto_otros%3D3620%26gasto_ colegios%3D240%26gasto_univ%3D340%26gasto_master%3D2230%26gasto_otros_gastos%3D7323433%26porc_gasto_ tarjetas%3D0%26porc_gasto_ibi%3D0%26porc_gasto_trib%3D0%26porc_gasto_seg_inm%3D0%26porc_gasto_seg_pe ns%3D0%26porc_gasto_seg_vida%3D2%26porc_gasto_seg_plan%3D2%26porc_gasto_seg_med%3D0%26porc_gasto_seg _coche%3D0%26porc_gasto_sum_luz%3D2%26porc_gasto_sum_agua%3D2%26porc_gasto_sum_gas%3D0%26porc_gasto_ sum_teleff%3D0%26porc_gasto_sum_telefm%3D0%26porc_gasto_sum_int%3D0%26porc_gasto_sum_tv%3D0%26porc_g asto_nivel_hogar%3D0%26porc_gasto_nivel_comida%3D0%26porc_gasto_nivel_cenas%3D0%26porc_gasto_nivel_v iajes%3D0%26porc_gasto_nivel_vacac%3D0%26porc_gasto_nivel_mob%3D0%26porc_gasto_nivel_ropa%3D20%26por c_gasto_nivel_transp%3D30%26porc_gasto_nivel_otros%3D30%26porc_gasto_colegios%3D2%26porc_gasto_univ% 3D0%26porc_gasto_master%3D0%26porc_gasto_otros_gastos%3D23%26tengo_casa1%3D1231.11%26tengo_casa2%3D1 0000%26tengo_casa3%3D22240%26tengo_otras%3D23560%26tengo_monetario%3D1212.34%26tengo_planpensiones%3 D23230%26tengo_otros%3D23330%26porc_tengo_casa1%3D1%26porc_tengo_casa2%3D0%26porc_tengo_casa3%3D2%26 porc_tengo_otras%3D0%26porc_tengo_monet%3D0%26porc_tengo_plan%3D0%26porc_tengo_otros%3D0%26debo_casa 1%3D4340%26debo_casa2%3D23450%26debo_casa3%3D23430%26debo_prestamo1%3D23330%26debo_prestamo2%3D6871. 11%26debo_prestamo3%3D11340%26debo_tarjetas%3D61340%26porc_debo_casa1%3D30%26porc_debo_casa2%3D10%26 porc_debo_casa3%3D12%26porc_debo_prestamo1%3D1%26porc_debo_prestamo2%3D12%26porc_debo_prestamo3%3D1% 26porc_debo_tarjetas%3D4%26plazo_debo_casa1%3D230%26plazo_debo_casa2%3D450%26plazo_debo_casa3%3D122% 26plazo_debo_prestamo1%3D3%26plazo_debo_prestamo2%3D12%26plazo_debo_prestamo3%3D4


It's 2568 characters long, so i guess that's why i get sometimes a GET undefined method in the web console.

The original function does something like this:


var param ="&usuario="+usuario+"&nivel="+nivel+gano+porc_gano+gasto+porc_gasto+tengo+porc_tengo+debo+porc_debo+plazo_debo;
var s = document.createElement("script");
s.type = "text/javascript"; s.async = true;
s.src = server_direction +"setMisDatos?callback=respuestaGuardarMisDatos&param="+encodeURIComponent(param);
var h = document.getElementsByTagName("script")[0];
h.parentNode.insertBefore(s, h); //or h.appendChild(s);

and every variable in the param is written like this:


var plazo_debo_casa1 = (getValor("plazo_debo_casa1"));
var plazo_debo_casa2 = (getValor("plazo_debo_casa2"));
var plazo_debo_casa3 = (getValor("plazo_debo_casa3"));
var plazo_debo_prestamo1 = (getValor("plazo_debo_prestamo1"));
var plazo_debo_prestamo2 = (getValor("plazo_debo_prestamo2"));
var plazo_debo_prestamo3 = (getValor("plazo_debo_prestamo3"));
var plazo_debo ="&plazo_debo_casa1="+plazo_debo_casa1+"&plazo_debo_casa2="+plazo_debo_casa2+"&plazo_debo_casa3="+plazo_debo_casa3+"&plazo_debo_prestamo1="+plazo_debo_prestamo1+"&plazo_debo_prestamo2="+plazo_debo_prestamo2+"&plazo_debo_prestamo3="+plazo_debo_prestamo3;

since my webpage has different parts where to put the data, i thought that a good idea would be to create smaller function for parts of variable, for example putting 30 variables and the do the callback. I did like this:


function guardaLoQueGano(){
var nivel = parseInt(document.getElementById('progreso_nivel_total').style.marginLeft);

/*idUsusario*/
var usuario = miGetElementsByClassName('title', document.getElementById('block-user-1'))[0].innerHTML;

/*gano*/
var gano_sal_neto = getValor("gano_sal_neto");
var gano_sal_prof = getValor("gano_sal_prof");
var gano_monet = getValor("gano_monet");
var gano_renta_fija = (getValor("gano_renta_fija"));
var gano_renta_vble = (getValor("gano_renta_vble"));
var gano_inmuebles = (getValor("gano_inmuebles"));
var gano_otros = (getValor("gano_otros"));
var gano_otros_ing = (getValor("gano_otros_ing"));

/*gano porcentajes*/
var porc_gano_monet = getValor("porc_gano_monet");
var porc_gano_rentaf = getValor("porc_gano_rentaf");
var porc_gano_rentav = getValor("porc_gano_rentav");
var porc_gano_inm = getValor("porc_gano_inm");
var porc_gano_otros = getValor("porc_gano_otros");
var porc_gano_otros_ing = getValor("porc_gano_otros_ing");

var param = "&usuario=" + usuario + "&nivel=" + nivel + "&gano_sal_neto=" + gano_sal_neto + "&gano_sal_prof=" + gano_sal_prof + "&gano_monet=" + gano_monet + "&gano_renta_fija=" + gano_renta_fija + "&gano_renta_vble=" + gano_renta_vble + "&gano_inmuebles=" + gano_inmuebles + "&gano_otros=" + gano_otros + "&gano_otros_ing=" + gano_otros_ing + "&porc_gano_monet=" + porc_gano_monet + "&porc_gano_rentaf=" + porc_gano_rentaf + "&porc_gano_rentav=" + porc_gano_rentav + "&porc_gano_inm=" + porc_gano_inm + "&porc_gano_otros=" + porc_gano_otros + "&porc_gano_otros_ing=" + porc_gano_otros_ing;

var s = document.createElement("script");

s.type = "text/javascript"; s.async = true;
s.src = direccion_servidor + "setMisDatos?callback=respuestaGuardarMisDatos&param=" + encodeURIComponent(param);
var h = document.getElementsByTagName("script")[0];
// adesso h.appendChild(s);
h.parentNode.insertBefore(s, h);
alert("Datos de lo que gano actualizados correctamente");
}

This kind of function works perfectly, but has a big problem: it changes the values of the columns of this function, but deletes the remaining ones. How can I create different smaller function, in a way to save only on some columns without changing the others? Shall I write the netbeans function setMisDatos to make it more clear?

Old Pedant
05-18-2012, 08:40 PM
You know, if you used POST data instead of putting it all in the querystring, there is no practical limit on the amount of data you can pass.

So you would have to change the Java code to retrieve POSTed data instead of GETed data, but that's a pretty simple change.

And then the way to send the posted data is easy: Submit a <form>. And if you want, the <form> can be 100% hidden.


<form id="HIDDEN" action="http://www.mirodinero.com:8080/mirodinero-war/setMisDatos" method="post">
<input type="hidden" name="callback" value="respuestaGuardarMisDatos" />
<input type="hidden" name="param" />
...
</form>

And then you could use JavaScript to put the data you need to pass into those <form> fields and then call the submit() method of the <form>.

Presto. No limits.

stokks
05-18-2012, 08:46 PM
and where shall i put this code? in the source code? or in the js file?

when you use "..." what do you mean? i'm sorry i'm really not an expert about this :o

thank you so much in advance!

Old Pedant
05-18-2012, 09:04 PM
The "..." was in case you needed other fields in the <form> (it means basically the same thing as "et cetera"), but I see that you don't. So omit that.

To put the value into the param field and then submit the form, you would just need to doe something like


var form = document.getElementById("HIDDEN");
form.param.value = param;
form.submit( );

Old Pedant
05-18-2012, 09:07 PM
Ahhh...but now that I see what you are doing, this is *NOT* going to work, at all.

You are having that URL produce JavaScript code for you that you then drop into your page.

So this is *NOT* going to work. Sorry! I led you in the wrong direction.

stokks
05-18-2012, 09:16 PM
ahhh it's ok ;) if someone answers it's ok, i can add as an information, that on the webpage (i'm working with drupal), there is a code for every button that works like this (it's in php):


<div class="generic botonGuardar">
<input type="button" value="Guardar" onclick="return guardaTodo()"/>
</div>

and guardaTodo() calls the function that creates that URL in javascript.

so maybe we are not so far from the solution, if you could help me it would be great ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum