Ciao, ho sfogliato tutto il forum con le key "ajax post" ma non ho trovato soluzione,
Ho una pagina "index.php" in questa pagina cè un div con id "box", dove viene caricata all'interno la pagina "add_fav.php" con un modulo con 1 campo.
Ora scrivendo nel campo e inviando, dovrebbe inviare alla pagina save_add_fav.php nello steddo div con id box.
Lo fa, ma non manda i dati, o non li recupera.. non so perchè, il mio JS è questo.
Codice PHP:
function get(sid){
if (document.all) {
return document.all[sid];
}
else if (document.layers) {
return document.layers[sid];
}
else if (document.getElementById) {
return document.getElementById(sid);
}
}
function getXMLHttpRequestInstance() {
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
function updateContent(nodeId, html) {
var node = get(nodeId);
if(null == node) {return;}
node.innerHTML = html;
node.style.visibility = "visible";
}
function ajax(nodeId, url, howsend, dati) {
var xmlhttp = getXMLHttpRequestInstance();
var metodo = howsend;
if(metodo == "POST"){
var valuein = dati;
var ok ="";
var stringa = new String;
stringa = dati;
var valori = new Array();
valori = stringa.split("+");
for (i=0;i<valori.length;i++)
{
var prova = valori[i];
ok +=(prova+"="+get(prova).value+"&");
}
contpost = ok;
}
if(!xmlhttp) {
alert("Il tuo browser non sopporta Ajax
È consigliato scaricare FireFox [url]www.firefox.com[/url]","Ajax");
return false;
}
updateContent(nodeId,"");
updateContent(nodeId,"[img]av/loader.gif[/img]");
// se metodo è GET
if(metodo == "GET"){
xmlhttp.open("GET", url,true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
updateContent(nodeId, xmlhttp.responseText);
} else if (xmlhttp.status==404) {
alert("Errore 404, il file cercato non esiste.","Ajax");
} else {
alert("Errore interno non gestito (" + xmlhttp.status + ")","Ajax");
}
}
}
xmlhttp.send(null);
// altrimenti se è post
}
else{
xmlhttp.open("POST", url, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
updateContent(nodeId, xmlhttp.responseText);
} else if (xmlhttp.status==404) {
alert("Errore 404, il file cercato non esiste.","Ajax");
} else {
alert("Errore interno non gestito (" + xmlhttp.status + ")","Ajax");
}
}
xmlhttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
}
xmlhttp.send(""+contpost+"");
xmlhttp.setRequestHeader("connection", "close");
}
}
la chiamata al form la faccio cosi
Codice PHP:
<form method="post" onsubmit="ajax('box', 'save_add_fav.php', 'POST', 'status+name'); return false;">
dove status è un input hidden e name il campo singolo dove scrivere il nome.
nella pagina che dovrebbe mettersi dentro il div "box", save_add_fav.php mi basterebbe recuperare un echo"$_POST[name]"; giusto per controllare che funzioni, poi salvare su database ecc è un attimo.
l'errore che mi da la console è
Codice PHP:
Errore: [Exception... "Component returned failure code: 0x804b000f (NS_ERROR_IN_PROGRESS) [nsIXMLHttpRequest.setRequestHeader]" nsresult: "0x804b000f (NS_ERROR_IN_PROGRESS)" location: "JS frame :: [url]http://www.pyrolog.ch/fav/main/mainjs.js[/url] :: anonymous :: line 112" data: no]
File sorgente: [url]http://www.pyrolog.ch/fav/main/mainjs.js[/url]
Riga: 112
se avete idee vi ringrazio anticipatamente.