通过jquery检查PHP脚本返回的数据 [英] checking returned data from PHP script through jquery

查看:57
本文介绍了通过jquery检查PHP脚本返回的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个PHP脚本

cch.php

$stmtcheck = $mysqli->prepare("SELECT id FROM members WHERE email=? AND unlock_code=?");
$stmtcheck->bind_param("si", $_SESSION['unlockemail'], $_POST['code']);
$stmtcheck->execute();
$stmtcheck->bind_result($id);
$stmtcheck->fetch();
$stmtcheck->close();

提交表格的jquery是

And jquery for submitting form is

recover.php

recover.php

$("#formUnlock").submit(function(e)
{
   e.preventDefault();

   $.ajax(
   {
        url: '../scripts/cch.php',
        method: 'POST',
        data: $(#formUnlock).serialize(),
        success: function()
        {
        alert("unlocked");
        }
   }); 
});

现在我要检查 $ id 有一些价值与否!我如何将 $ id 变量提取到我的主脚本?

Now what I want to check whether $id has some value or not! How would I fetch the $id variable to my main script?

推荐答案

在cch.php中,如果你只想将一个id传递给javascript,你可以打印id

In cch.php, if you want to pass only an id to the javascript, you can print id

echo $id;

ajax响应收到的数据将作为参数传递给成功回调函数。您必须在succes回调中执行成功操作或者您必须编写一个函数以在ajax成功时执行并调用该函数并传递参数

What ever data is received on ajax response will be passed as parameter to the success callback function. Either you have to execute the success actions inside the succes call back OR You have to write a function to be executed on ajax success and call that function and pass the params

$("#formUnlock").submit(function(e)
{
   e.preventDefault();

   $.ajax(
   {
        url: '../scripts/cch.php',
        method: 'POST',
        data: $(#formUnlock).serialize(),
        success: function(responseData)
        {
            if (responseData == '' )
            {
                 alert("Sorry failed");
            }
            else
            {
                alert("Success");
            }
        }
   }); 
});

这篇关于通过jquery检查PHP脚本返回的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆