Loading dynamic external form with jquery
I hope someone could help me.
When i load an external php that generates a set of fields, i have no problems, but then i send the generated form, i can not access the vars.
There is the code i user:
For load the external file:
$.ajax({
type: "POST",
url: "product-insert.php",
contentType: "application/x-www-form-urlencoded",
global: true,
processData:true,
dataType: 'html',
data: {num_filas: $("#num_filas").val()},
success: function(html){
$("#destino").html(html);
alert(html);
str = $("ofertas").serialize();
},
error: function(){
},
complete: function(){
}
});
<form action="ofertas.php开发者_运维技巧" method="post" enctype="multipart/form-data" name="form-ofertas" id="ofertas" >
<div id="destino"></div>
The file loaded have this code:
echo '<input name="campo" type="hidden" value="valor" />';
and the php file that receive the form have this code:
die("campo: ".$_REQUEST['campo']);
I really will appreciate a lot the help.
Thnx in advance.
Yannick
Based upon your comment, you're checking for $_POST['campo']
despite the fact that your <form>
tag's method is a GET request. You should instead check the value of $_GET['campo']
(or $_REQUEST['campo']
).
I'm guessing partially off comments here, your form looks like this:
<form action="ofertas.php" method="get" enctype="multipart/form-data"
name="form-ofertas" id="ofertas">
<div id="destino"></div>
</form>
Your method is GET
, which won't give you what you're after if you're looking for the values in the POST
collection, which $_POST
does. Just change the method on your form to method="post"
to get this working correctly, otherwise use $_GET
on the PHP side, if a GET is what you're actually after.
For a good discussion of GET vs POST, take a look here:
When do you use POST and when do you use GET?
精彩评论