Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic including javascript with jquery
    text
    copied!<p>I'm facing a problem using IE here. I need to insert a form on distinct web pages in distinct servers and domains. I'm doing this through a javascript include like this:</p> <pre><code>&lt;script type="text/javascript" src="http://www.sisgol.com.br/teste/write_js.php?content=form_content"&gt;&lt;/script&gt; &lt;div id="form_hypescience"&gt; &lt;/div&gt; </code></pre> <p>The include loads the following content into the div:</p> <pre><code>$(document).ready(function(){ $('#form_hypescience').html('\ &lt;style&gt;\n\ #form_hypescience {\n\ width: 250px;\n\ height: 250px;\n\ }\n\ #form_hypescience p {\n\ margin: 0;\n\ padding: 0;\n\ }\n\ #form_hypescience label {\n\ font-size: x-small;\n\ display: block;\n\ }\n\ #form_hypescience input[type=text], textarea{\n\ font-size: x-small;\n\ width: 240px;\n\ }\n\ #form_hypescience textarea {\n\ height: 40px;\n\ }\n\ #form_hypescience button {\n\ background:#000000 none repeat scroll 0 0;\n\ border: medium none;\n\ color: #e7e7e7;\n\ padding: 1px;\n\ font-size: 60%;\n\ }\n\ \n\ &lt;/style&gt;\n\ \n\ &lt;form class="form_hypescience" method="post" action="&lt;!URL_PROCESS_FORM_DATA!&gt;"&gt;\n\ &lt;p&gt;\n\ &lt;label for="nome"&gt;Seu Nome&lt;/label&gt;\n\ &lt;input type="text" id="nome" name="nome" size="30" /&gt;\n\ &lt;/p&gt;\n\ &lt;p&gt;\n\ &lt;label for="email"&gt;Seu e-mail&lt;/label&gt;\n\ &lt;input type="text" id="email" name="email" size="30" /&gt;\n\ &lt;/p&gt;\n\ &lt;p&gt;\n\ &lt;label for="emails_amigos"&gt;E-mail dos seus amigos&lt;/label&gt;\n\ &lt;textarea id="emails_amigos" name="emails_amigos" cols="10" rows="3"&gt;&lt;/textarea&gt;\n\ &lt;/p&gt;\n\ &lt;p&gt;\n\ &lt;label for="mensagem"&gt;Mensagem&lt;/label&gt;\n\ &lt;textarea id="mensagem" name="mensagem" cols="10" rows="3"&gt;&lt;/textarea&gt;\n\ &lt;/p&gt;\n\ &lt;p&gt;\n\ &lt;label for="captcha"&gt;Digite o texto ao lado&lt;/label&gt;\n\ &lt;input type="text" id="captcha" name="captcha" size="15" /&gt;\n\ &lt;/p&gt;\n\ &lt;button type="button" id="enviar"&gt;Enviar&lt;/button&gt;\n\ &lt;/form&gt;\n\ &lt;span id="retorno_envio_form"&gt;&lt;/span&gt;' ); $('#enviar').click(function(){ var parametros = new Array(); parametros.push('nome=' + $('#nome').val()); parametros.push('email=' + $('#email').val()); parametros.push('emails_amigos=' + $('#emails_amigos').val()); $('#retorno_envio_form').html('\ &lt;script type="text/javascript" \n\ src="&lt;!URL_PROCESS_FORM_DATA!&gt;?' + encodeURI(parametros.join('&amp;')) + '"&gt;&lt;/script&gt;\n\ '); });}); </code></pre> <p>I'm sending the the form data through a javascript include (because the security model of the browsers regarding requests to distinct domains). In FireFox the code is working nicely and I was just wondering the next step when I noticed that this code on Microsoft Browsers send the request twice when the button is clicked. I used a program called Fiddler to confirm the fact.</p> <p>This is an example of the first request:</p> <p><strong>GET /teste/process_form.php?nome=maria%20&amp;email=o%20cara&amp;emails_amigos=um@email.com HTTP/1.1</strong></p> <p>now the second request (that happens just after the first):</p> <p><strong>GET /teste/process_form.php?nome=maria%20&amp;email=o%20cara&amp;emails_amigos=um@email.com&amp;_=1251168480125 HTTP/1.1</strong></p> <p>I've tried use preventDefault() (returning false in the end of the function), cut the form off, use a input type='submit' instead of a button, use a link instead of a button, create the script using the $('body').append(). Someone has any idea to help here?</p> <p>Thanks in advance. ps: the code that I tried like seth said:</p> <pre><code>$('#data_form').submit(function(){ var parametros = new Array(); parametros.push('nome=' + $('#nome').val()); parametros.push('email=' + $('#email').val()); parametros.push('emails_amigos=' + $('#emails_amigos').val()); parametros.push('mensagem=' + $('#mensagem').val()); $('#retorno_envio_form').html('\ &lt;script type="text/javascript" \n\ src="&lt;!URL_PROCESS_FORM_DATA!&gt;?' + encodeURI(parametros.join('&amp;')) + '"&gt;&lt;/script&gt;\n\ '); return false; }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload