Form submit not happening when I set target attribute using jquery
I have the form inside iframe, I have the followi开发者_如何学编程ng piece of code
<script type="text/javascript">
var Path="<?= $this->url ?>"
$(function()
{
vReg=0
$("#signin").submit(function()
{
if(vReg == 1)
{
return true;
}
else{
var url = Path;
var data = {};
$("input").each(function()
{
data[$(this).attr('name')] = $(this).val();
});
$("select").each(function()
{
data[$(this).attr('name')] = $(this).val();
});
$.post(url,data,function(resp)
{
vError=""
for(id in resp){
oResp=resp[id];
for(key in oResp){
vError +=oResp[key]+"\n"
}
}
if(vError == ''){
vReg=1;
$("#formid").attr('target','_top');
$("#signin").submit();
return true;
}
else{
$("#formid").attr('target','_self');
alert(vError)
}
return false;
},'json');
return false;
}
});
});
</script>
My aim is, If I have no Error, I will apply this target attribute and then immediately submit the form which takes the page to parent page. But I got target attribute when I click form submit for the first time,again click the second time its now redirecting to parent page. I need it happens when i click first time itself.
Kindly help
Finally i got it by using button instead of submit Action in form and also having changes in code ,
<script type="text/javascript">
var Path="<?= $this->url ?>"
$(function()
{
vReg=0
$("#signinbtn").click(function()
{
if(vReg == 1)
{
return true;
}
else{
var url = Path;
var data = {};
$("input").each(function()
{
data[$(this).attr('name')] = $(this).val();
});
$("select").each(function()
{
data[$(this).attr('name')] = $(this).val();
});
$.post(url,data,function(resp)
{
vError=""
for(id in resp){
oResp=resp[id];
for(key in oResp){
vError +=oResp[key]+"\n"
}
}
if(vError == ''){
vReg=1;
$("#formid").attr('target','_top');
$("#signin").submit();
return true;
}
else{
$("#formid").attr('target','_self');
alert(vError);
return false;
}
},'json');
//return false;
}
});
});
</script>
But i still dont know why submit function is not working here,Any idea ?
精彩评论