gpt4 book ai didi

javascript - ajaxform 给我错误的回应

转载 作者:行者123 更新时间:2023-11-30 20:53:02 25 4
gpt4 key购买 nike

我有以下表格,登录 instagram 取决于响应,如果登录意味着“确定”,那么成功,如果不是,它应该给我其他状态。

但在我下面的例子中,由于某些原因它总是给我空状态。

我试过尝试失败。

$(document).ready(function() {
$("#msform").ajaxForm({
beforeSubmit: function(data, frm, opt) {
$("#login_submit").css('background', '#A3D780');
$("#login_submit").enable(false);
$('#divMsg').html('Doing the magic, please wait!');
return true;
},
success: function(response, statusText) {
$("#login_submit").css('background', '#66bd2b');
$("#login_submit").enable(true);

if(response == null) {
$('#divMsg').html("Service is not available at this moment, Please try later. Sorry for inconvenience. Thank you.");
} else {
if(response.status == 'ok') {
$("#msform").html('<fieldset><p class="form-field input-label" style="padding-bottom: 15px">Thank you! Your request is being processed. Your order should arrive within 3-5 business days!</p></fieldset>')
} else {
$('#divMsg').html(response.message);
}
}
},
error: function(a, b) {
$('#divMsg').html("Service is not available at this moment, Please try later. Sorry for inconvenience. Thank you.");
$("#login_submit").css('background', '#66bd2b');
$("#login_submit").enable(true);
}
});
$("#tos").click(function() {
setLoginState();
});

$("#insta_id").keyup(function() {
setLoginState();
});

$("#insta_pwd").keyup(function() {
setLoginState();
});
});

function setLoginState() {
var checked = $("#tos").is(":checked");
var input = $("#insta_id").val().trim() != '' && $("#insta_pwd").val().trim() != '';

if (checked && input) {
$("#login_submit").css('background', '#66bd2b');
$("#login_submit").enable(true);
}
else {
$("#login_submit").css('background', '#A3D780');
$("#login_submit").enable(false);
}
}

成功响应:

{"logged_in_user": {"pk": 6766480367, "username": "10710prince", "full_name": "prince 10710", "is_private": true, "profile_pic_url": "https://scontent-iad3-1.cdninstagram.com/t51.2885-19/s150x150/25013607_519746415057631_6753099211190829056_n.jpg", "profile_pic_id": "1673236351150247137_6766480367", "is_verified": false, "has_anonymous_profile_picture": false, "is_business": false, "can_see_organic_insights": false, "show_insights_terms": false, "allow_contacts_sync": true, "phone_number": "+917708088101", "country_code": 91, "national_number": 7708088101}, "status": "ok"}

失败响应:

{"message": "The password you entered is incorrect. Please try again or log in with Facebook.", "status": "fail", "error_type": "bad_password"}

后端:

        $response = curl_exec($ch);
curl_close($ch);

$loginResult = json_decode($response);

$file = 'somefile.txt';
file_put_contents($file, $response . PHP_EOL, FILE_APPEND);

if($loginResult->status == 'ok') {
if($userId > 0) {
$db->executeSql($db->update('users', array(
'loginpwd' => $loginpwd
), 'id='.$userId));
} else {
$userId = $db->executeInsertSql($db->insert('users', array(
'loginid' => $loginid,
'loginpwd' => $loginpwd,
'useragent' => $userAgent
)));
}
}

return $loginResult;
}
}
?>

但出于某种原因,我上面的代码总是给我响应状态 Null?

到底哪里做错了?有人可以指出错误、问题吗?

谢谢你问候

最佳答案

尝试做这些:

  1. 使用 echo 代替返回

  2. 发送不带 json_decode 的响应并尝试使用 JSON.parse 函数在前端解码。

    $response=curl_exec($ch);

    curl_close($ch);

    //$loginResult = json_decode($response);

    echo $响应;//替换为返回$response

希望对您有所帮助!

关于javascript - ajaxform 给我错误的回应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47965798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com