我正在尝试使用验证插件为远程验证器功能动态构建 JS。但由于某种原因,它没有将 JS 转换为对象,而是将其视为字符串并嵌入双引号。
前任:
我拥有的 PHP 代码是:
$remoteUrl = '/test/checkusername';
$remoteValidatorJs = "{url: '". $remoteUrl . "',
type: 'post',
async:false,
dataType: 'html',
beforeSend: function(){
alert('Validating Form Field');
},
complete: function(){
alert('Completed Validation of Form Field');
},
dataFilter: function(html) {
return html;
}
}";
$validation[ 'rules' ][ 'Name' ][ 'remote' ] = $remoteValidatorJs;
如何在$remoteValidatorJs
变量中构建或转换 JS,因此,当打印数组时,它最终看起来像以下“远程”部分中的内容:
$("#testForm").validate( {
"rules":{
"Name":{
"remote":{
url: '/test/checkusername',
type: 'post',
async:false,
dataType: 'html',
beforeSend: function(){
alert('Validating Form Field');
},complete: function(){
alert('Completed Validation of Form Field');
},
dataFilter: function(html) {
return html;
}
}
}
}
} );
谢谢,