到目前为止,我一直使用普通 dataType 'html' 的 AJAX 帖子,现在我将其转换并使用 dataType 'json' ,
现在,在我使用 json 之前,我将响应错误与输入字段旁边的每个跨度分开。
这是我使用普通数据类型 'html' 的旧 ajax succses 拆分错误代码:
success:
function(data){
var data_array = split('*');
for(var i=0; i<data_array.length-1; i++)
{
messgae_array = data_array[i].split(':');
$("#"+messgae_array[0]+"_error").html(messgae_array[1]);
$("#"+messgae_array[0]).css({"border":"1px solid red"});
}
}
这是我在表格上的输入
<input type="text" id="uname" name="uname" value="" class="inplaceError" />
<span id="uname_error"></span>
我有更多的输入,我只是输入了它的外观..
所以我的每个输入都有跨度,它包含来自 ajax 响应的错误。
现在的问题是我的旧代码知道处理 html 响应而不是 json 响应,我是 javascript/ajax/json 新手,我不知道如何更改拆分代码,所以使用 json 响应而不是正常的 html 响应,请帮助?
编辑:
我触发这样的错误:
if(isset($_POST['p']) && !empty($_POST['p']))
{
if($password == $retype)
{
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
// Create salted password (Careful with the chilli)
$password = hash('sha512', $password.$random_salt);
}
else
{
$message['password']=' password not match';
}
and so on .
$message['email']=' wrong email';
和我的 foreach json 数组的错误:
foreach($message as $key => $val) {
$return = array('error' => $key, 'message' => $val );
echo json_encode($return);
}
所以这里的一些东西是错误的,因为错误是错误的,因为 ajax 响应代码是错误的,有什么想法吗?