Autor | Zpráva | ||
---|---|---|---|
Pinqui Profil |
#1 · Zasláno: 25. 7. 2009, 11:56:41
Dobrý den chtěl bych se zeptat, používám tyto scripty, už mailnko upravené:
/* * @copyright Jakub Vrána, http://php.vrana.cz */ function send_xmlhttprequest(state_change, method, url, content, headers) { var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false)); if (!xmlhttp) { return false; } xmlhttp.open(method, url); xmlhttp.onreadystatechange = function () { state_change(xmlhttp); }; headers = headers || {}; headers['X-Requested-With'] = headers['X-Requested-With'] || 'XMLHttpRequest'; for (var key in headers) { xmlhttp.setRequestHeader(key, headers[key]); } xmlhttp.send(content); return true; } function post_xmlhttprequest(state_change, url, form, headers) { var elements = form.elements; var content = []; for (var i=0; i < elements.length; i++) { if (elements[i].attributes.name && elements[i].attributes.name.specified && !elements[i].disabled) { if (/^(select)$/i.test(elements[i].tagName)) { var options = elements[i].options; for (var j=0; j < options.length; j++) { if (options[j].selected) { var value = (options[j].attributes.value && options[j].attributes.value.specified ? options[j].value : options[j].text); content.push(encodeURIComponent(elements[i].name) + '=' + encodeURIComponent(value)); } } } else if (!/^(submit|reset|button|file|image)$/i.test(elements[i].type) && (!/^(radio|checkbox)$/i.test(elements[i].type) || elements[i].checked)) { content.push(encodeURIComponent(elements[i].name) + '=' + encodeURIComponent(elements[i].value)); } } } if (!headers) { headers = {}; } headers['Content-Type'] = 'application/x-www-form-urlencoded'; return send_xmlhttprequest(state_change, 'POST', url, content.join('&'), headers); } a u formuláře přímo: function cleanSpan(id){ document.getElementById(id).innerHTML = ''; } function odeslat(form) { clearTimeout(clean); document.getElementById('stav').innerHTML = 'Odesílá se.'; form.submit.disabled=true; return post_xmlhttprequest(function (xmlhttp) { form.text.value = form.text.defaultValue; if (xmlhttp.readyState == 4) { document.getElementById('stav').innerHTML = 'Odesláno'; form.submit.disabled=false; document.getElementById('txt').focus(); clean = setTimeout("cleanSpan('stav');",2000); } }, './data.php?akce=form&r=<?php print $_GET["rid"]; ?>', form); } Odezva by byla například: funkce1(); funkce2(); status = "ok"; jak udělat, aby se to co je v odezvě uskutečnilo? stránka: hlavička <script> status = '0'; funkce1(){...} funkce2(){...} </script> tělo <form action="" method="post" onsubmit="return !odeslat(this);"> <label for="txt"><?php print $_SESSION[nick']; ?>: </label><input type="text" name="text" id="txt" autocomplete="off" maxlength="400" onkeydown="Complete(event,this);"> <input type="checkbox" name="wisp" id="check"> <select name="to" id="to"><option value="0">vyčkejte prosím</select> <input type="submit" name="submit" value="Odešli"> <span id="stav"></span> </form> patička děkuji |
||
Pinqui Profil |
#2 · Zasláno: 25. 7. 2009, 23:24:52
Opravdu nikdo neví?? Prosím?? Potřebuji když se ten formulář oděšle tak php script uloží záznam do databáze - status = ok; když odešle prázdnej text pošle status = "empty" když pošle dvakrat posobě stejný přízpěvek napíše status = "double" . Mám dojem že se to nějak dělá s callback, jenže nevím jak dostat informace z vkládaných scriptů..
|
||
Pinqui Profil |
#3 · Zasláno: 26. 7. 2009, 09:12:15 · Upravil/a: Pinqui
Vyřešeno.. prosím kdyžtak komentáře děkuji k řešení:
function fetchForm(id, callback) { var oScript = document.getElementById(id); if (oScript && oScript.readyState && oScript.readyState != 'loaded') { return } var head = document.getElementsByTagName("head")[0]; if (oScript) { head.removeChild(oScript); } oScript = document.createElement("script"); head.appendChild(oScript); oScript.innerHTML = callback; oScript.id = id; oScript.type = 'text/javascript'; } zkoušel jsem i toto pořád stejný problém: function fetchForm(id, callback) { var CScript = document.getElementById(id); if (CScript && CScript.readyState && CScript.readyState != 'loaded') { return } var head = document.getElementsByTagName("body")[0]; if (CScript) { head.removeChild(CScript); } var CScript = document.createElement("script"); var callback = callback; var ss = document.createTextNode(callback); CScript.appendChild(ss); CScript.id = id; CScript.type = 'text/javascript'; head.appendChild(CScript); } a upravil jsem první kód: upravovaná část: xmlhttp.open(method, url); xmlhttp.onreadystatechange = function () { state_change(xmlhttp); }; upravená část: xmlhttp.open(method, url); xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ fetchForm('scriptFORM',xmlhttp.responseText); } state_change(xmlhttp); }; // edit tak jsem přišel na to, že mi to hlásí chybu u: oScript.innerHTML = callback; v internet explorer v ff to funguje jak má. script se natom zasekne a nejde dál (objekt je null nebo není definován) Bohužel ie nemá firebug pro to abych koukl co z toho to opravdu je // připadá mi, jakoby se element v ie nevytvořil ale nechápu důvod |
||
Pinqui Profil |
#4 · Zasláno: 26. 7. 2009, 18:34:30
Vyřešeno:
function fetchForm(id, callback) { var CScript = document.getElementById(id); if (CScript && CScript.readyState && CScript.readyState != 'complete') { return } var head = document.getElementsByTagName("head")[0]; if (CScript) { head.removeChild(CScript); } var CScript = document.createElement('script'); CScript.text = callback; head.appendChild(CScript); CScript.id = id; CScript.type = 'text/javascript'; } funguje jak v ie tak ff dále jsem nezkoušel |
||
Časová prodleva: 15 let
|
0