encodeURIcomponent fails the first time (need two clicks to work)
i'm working with a javascript on a drupal website, but the saving function seems to work only as soon as i click 2 times on the "save" button. the code that fires the function is:
Code:
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 = direccion_servidor +"setMisDatos?callback=respuestaGuardarMisDatos¶m="+encodeURIComponent(param);
h = document.getElementsByTagName("script")[0];
h.parentNode.insertBefore(s, h);
i got the parentNode.insertBefore code from google (the same they use in google analitycs), but still i get error (specifically when he has to do the parentNode.insertBefore part (earlier it was only appendChild, but used to give me the same kind of error. Are the spaces a problem in this sense? Or there might be a better solution? because if i click the second time it enters the setMisDatos function and then works 100%. This is really driving me crazy, can anybody help me?
i tried it, but it still doesn't work.. in the netbeans logger, it actually works only if it can enter the setMisDatos function, while when it doesn't work, nothing appears on the logger (making me think that the function is not called). any suggestion?
i even tried changing the encodeURIcomponent with encodeURI, but it still creates problem, what i thinkis that if it doesn't work the first time but then always, i don't believe there is something incorrect with the variables no?
isn't there a tool to help me check the error better than firefox or chrome web console?
Bookmarks