No funciona.
Si utilizo un botón submit funciona sin problemas. Pero en la página desde donde tiene que enviarse no puede haber ningún botón. El formulario está compuesto por campos ocultos y esto es totalmente transparente para el usuario.
Agredecería muchísimo si alguien me puede dar o una solución con estas mismas herramientas o alguna sugerencia con otro tipo de herramientas.
Pongo el código (simplificado) para que se vea como estoy intentando hacerlo.
Cita:
recibe.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<script>
// prepare the form when the DOM is ready
$(document).ready(function() {
var options = {
// target: '#output1', // target element(s) to be updated with server response
beforeSubmit: cargodatos, // pre-submit callback
success: showResponse // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
};
// bind form using 'ajaxForm'
$('#frmcookie').ajaxForm(options);
});
// post-submit callback
function showResponse(responseText) {
// for normal html responses, the first argument to the success callback
// is the XMLHttpRequest object's responseText property
// if the ajaxForm method was passed an Options Object with the dataType
// property set to 'xml' then the first argument to the success callback
// is the XMLHttpRequest object's responseXML property
// if the ajaxForm method was passed an Options Object with the dataType
// property set to 'json' then the first argument to the success callback
// is the json data object returned by the server
alert('respuesta: ' + responseText);
}
function cargodatos() {
document.frmcookie.source.value = "hola";
document.frmcookie.medium.value = "adios";
document.frmcookie.term.value = "jejeje";
document.frmcookie.content.value = "jijiji";
return true;
}
</script>
</head>
<body>
<form name="frmcookie" id="frmcookie" method="post" action="recibe.php">
<input type="hidden" name="source" id="source" />
<input type="hidden" name="medium" id="medium" />
<input type="hidden" name="term" id="term" />
<input type="hidden" name="content" id="content" />
<input type="hidden" name="campaign" id="campaign" />
<input type="hidden" name="segment" id="segment" />
</form>
<script>document.frmcookie.submit(); alert('hola');</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<script>
// prepare the form when the DOM is ready
$(document).ready(function() {
var options = {
// target: '#output1', // target element(s) to be updated with server response
beforeSubmit: cargodatos, // pre-submit callback
success: showResponse // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
};
// bind form using 'ajaxForm'
$('#frmcookie').ajaxForm(options);
});
// post-submit callback
function showResponse(responseText) {
// for normal html responses, the first argument to the success callback
// is the XMLHttpRequest object's responseText property
// if the ajaxForm method was passed an Options Object with the dataType
// property set to 'xml' then the first argument to the success callback
// is the XMLHttpRequest object's responseXML property
// if the ajaxForm method was passed an Options Object with the dataType
// property set to 'json' then the first argument to the success callback
// is the json data object returned by the server
alert('respuesta: ' + responseText);
}
function cargodatos() {
document.frmcookie.source.value = "hola";
document.frmcookie.medium.value = "adios";
document.frmcookie.term.value = "jejeje";
document.frmcookie.content.value = "jijiji";
return true;
}
</script>
</head>
<body>
<form name="frmcookie" id="frmcookie" method="post" action="recibe.php">
<input type="hidden" name="source" id="source" />
<input type="hidden" name="medium" id="medium" />
<input type="hidden" name="term" id="term" />
<input type="hidden" name="content" id="content" />
<input type="hidden" name="campaign" id="campaign" />
<input type="hidden" name="segment" id="segment" />
</form>
<script>document.frmcookie.submit(); alert('hola');</script>
</body>
</html>
Cita:
Gracias por la ayuda. <?php
$source = $_POST['source'];
$medium = $_POST['medium'];
$term = $_POST['term'];
$content = $_POST['content'];
echo $source."<br />";
echo $medium."<br />";
echo $term."<br />";
echo $content."<br />";
?>
$source = $_POST['source'];
$medium = $_POST['medium'];
$term = $_POST['term'];
$content = $_POST['content'];
echo $source."<br />";
echo $medium."<br />";
echo $term."<br />";
echo $content."<br />";
?>