如何将PHP中的数据转换为Javascript?
我有一个由PHP脚本生成的错误消息,我想将该消息放入JavaScript中以显示电子邮件验证的结果。
我完成了输入表单为空的情况下的错误验证脚本,
现在我很困惑,如果输入表单不是空的,并且电子邮件验证成功,如何获得成功消息。
有人能帮我吗?
这是我的PHP代码:
{"error":1,"info":[
{"fieldId":"contact-form-name","message":"Please enter your name."},
{"fieldId":"contact-form-mail","message":"Please enter valid e-mail."},
{"fieldId":"contact-form-message","message":"Please enter your message."}]}这是我的JavaScript代码:
;(function($,doc,win) {
"use strict";
var contactForm=function(object,option)
{
/**********************************************************************/
var $self=this;
var $this=$(object);
var $option=option;
/**********************************************************************/
this.build=function()
{
$this.bind('submit',function(e)
{
e.preventDefault();
$self.submit();
});
};
/**********************************************************************/
this.submit=function()
{
this.blockForm(true);
<!--$.post('plugin/contact-form/contact-form.php',$this.serialize(),this.processResponse,'json');-->
$.post('plugin/contact-form/contact-form.php',$this.serialize(),this.processResponse,'json');
};
/**********************************************************************/
this.processResponse=function(response)
{
$self.blockForm(false);
$this.find('li').qtip('destroy');
var error=false;
if(typeof(response.info)!='undefined')
{
if(response.info.length)
{
for(var key in response.info)
{
error=error || response.error;
$('#'+response.info[key].fieldId).parents('li:first').qtip(
{
show :
{
target : $(this)
},
style :
{
classes : (response.error==1 ? 'template-qtip template-qtip-error' : 'template-qtip template-qtip-success')
},
content :
{
text : response.info[key].message
},
position :
{
my : 'bottom center',
at : 'top center'
}
}).qtip('show');
}
}
}
if(!error)
{
$this.find('input[type="text"],textarea').val('').blur();
window.setTimeout(function()
{
$('#contact-form-submit').qtip('destroy');
},2000);
}
};
/**********************************************************************/
this.blockForm=function(block)
{
if(block) $this.find('li').block({message:false,overlayCSS:{opacity:'0.3'}});
else $this.find('li').unblock();
};
/**********************************************************************/
}
/**************************************************************************/
$.fn.contactForm=function(option)
{
return this.each(function()
{
var object=new contactForm(this,option);
object.build();
return(object);
});
};
})(jQuery,document,window);这是我的表格:
<form name="contact-form" id="contact-form" method="post">
<ul class="template-reset-list template-clear-fix">
<li>
<label for="contact-form-name" class="template-infield">Name (required)</label>
<input type="text" name="contact-form-name" id="contact-form-name"/>
</li>
<li>
<label for="contact-form-mail" class="template-infield">E-mail (required)</label>
<input type="text" name="contact-form-mail" id="contact-form-mail"/>
</li>
<li>
<label for="contact-form-website" class="template-infield">Websiste</label>
<input type="text" name="contact-form-website" id="contact-form-website"/>
</li>
<li>
<label for="contact-form-subject" class="template-infield">Subject</label>
<input type="text" name="contact-form-subject" id="contact-form-subject"/>
</li>
<li>
<label for="contact-form-message" class="template-infield">Message (required)</label>
<textarea name="contact-form-message" id="contact-form-message"></textarea>
</li>
<li>
<label for="contact-form-submit" class="template-infield"></label>
<input type="submit" name="contact-form-submit" id="contact-form-submit" value="Submit"/>
</li>
</ul>
</form>发布于 2016-05-14 02:47:54
我认为你是在试图通过预览来获取一个受版权保护的模板。通过购买模板来支持开发人员-您不仅可以获得正确的模板文件、php插件,还可以获得开发人员本人的技术支持。
https://stackoverflow.com/questions/32131945
复制相似问题