Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从php到ajax的数据发布_Php_Jquery_Mysql_Ajax - Fatal编程技术网

从php到ajax的数据发布

从php到ajax的数据发布,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我正在使用这个jquery,我想将数据从php发送到jquery,但它不起作用。如果我没有使用json,它可以正常工作。但我想让json知道哪个用户登录了,他是建设者、经销商还是个人,我是jquery新手 <script> $(document).ready(function() { $("#LoginForm").submit(function(e) { $("#simple-msg1").html("<img src='img/lo

我正在使用这个jquery,我想将数据从php发送到jquery,但它不起作用。如果我没有使用json,它可以正常工作。但我想让json知道哪个用户登录了,他是建设者、经销商还是个人,我是jquery新手

<script>

  $(document).ready(function()
  {
    $("#LoginForm").submit(function(e)
    {

      $("#simple-msg1").html("<img  src='img/loading.gif'/>");
      var postData ="";
      postData = $(this).serializeArray();
      //alert(postData);

      var formURL = $(this).attr("action");

      $.ajax(
      {
        url : formURL,
        type: "POST",
        data : postData,
        contentType: "application/json; charset=utf-8",
        dataType:"json",
        success:function(data,textStatus,jqXHR)
        {
          alert("successss");
          $("#simple-msg1").html('<pre><code class="prettyprint"> Login Successfull </code></pre>');

          if(data.message == 'Dealer')
          {
            // window.location = "Dealer/EditLoginDetails.php?Login=successfull";
            alert("Wellcome Dealer");
          }
          else if(data.message == 'Individual')
          {
            alert("Wellcome Individual");
          }
          else if(data.message == 'Builder')
          {
            alert("Wellcome Builder");
          }




          //return true;
        },
        error:function(jqXHR, textStatus, errorThrown)
        {
          alert("failer");
          $("#simple-msg1").html('<pre><code class="prettyprint">  </code></pre>');

          $("#simple-msg1").html('<pre><code class="prettyprint"> wrong username or password </code></pre>');
        }
      });
      e.preventDefault(); //STOP default action
    });

    $("#Button1").click(function()
    {

      $("#LoginForm").submit(); //SUBMIT FORM
    });

  });

</script>

$(文档).ready(函数()
{
$(“#LoginForm”).submit(函数(e)
{
$(“#simple-msg1”).html(“”);
var postData=“”;
postData=$(this.serializeArray();
//警报(postData);
var formURL=$(this.attr(“操作”);
$.ajax(
{
url:formURL,
类型:“POST”,
数据:postData,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:函数(数据、文本状态、jqXHR)
{
警报(“成功”);
$(“#simple-msg1”).html(“登录成功”
”; 如果(data.message==“经销商”) { //window.location=“Dealer/EditLoginDetails.php?Login=successfull”; 警惕(“威康经销商”); } else if(data.message==“个人”) { 警惕(“威康个人”); } else if(data.message=='Builder') { 警惕(“威康建筑商”); } //返回true; }, 错误:函数(jqXHR、textStatus、errorshown) { 警惕(“失败者”); $(“#simple-msg1”).html('); $(“#simple-msg1”).html(“错误的用户名或密码””; } }); e、 preventDefault();//停止默认操作 }); $(“#按钮1”)。单击(函数() { $(“#LoginForm”).submit();//提交表单 }); }); 这是检查登录页面


我认为脚本中不需要这一行

试试看


在php页面中,也不需要内容类型标题

您从AJAX中得到了哪些错误消息?AJAX响应是什么样子的?“它不工作”-到底什么不工作?你有错误吗?你能找出是哪部分代码导致了这个问题吗?我的php技能已经生锈了。我一直在使用python。如果我没有弄错的话,json要求您将其作为参数添加,因为json只是javascript的一种格式。您需要将用户添加到数据中的ajax调用中。python有一种方法可以从post中获取json数据,然后检查参数。也许从这个开始,它总是显示错误消息控制不成功
<?php
header("Content-Type: application/json");
ob_start();

if(session_id() == '')
                 {
                   session_start();
                }


//include 'CUserDB.php';


include 'config.php';
 $error = "success";
    $message = '';
    $redirect = '';


$myusername=$_POST['txtusername']; 
$mypassword=$_POST['txtpassword']; 

//$myusername="deepak"; 
//$mypassword="deepak"; 


$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);

$myusername = mysql_real_escape_string($myusername);
$mypassword=mysql_real_escape_string($mypassword);

$str="select VerificationCode from user_verification where UserName='".$myusername."'";
$result=mysql_query($str) or die ("Queryfailed");
$UserData=mysql_fetch_array($result);
//if($UserData['VerificationCode']!='' && $UserData['VerificationCode']!=NULL)
//{
    //echo "<script type='text/javascript'> alert('Please Enter the verification code first.') ";
    //echo "<script>  window.location.href='VerifyUser.php?UName=".$Uname."'"; 


 // return 0;   
//}
//else
//{         
$qry = "SELECT UserName,Type_user FROM login WHERE UserName = '".$myusername."' AND password = '".$mypassword."' ";

$result = mysql_query($qry) or die ("Query failed");

$UserData = mysql_fetch_array($result);

    if($UserData['UserName'] != '')

        {
        //echo $UserData['UserName'];



             $_SESSION['UserId'] = $myusername;

        $typ = $UserData['Type_user'];

          $_SESSION['Typeuser'] = $UserData['Type_user'];


    if($typ == "Dealer")
    { 
    $message = "Dealer";

    //  header('location:Dealer/EditLoginDetails.php');


    }
    else if($typ == "Individual")
    {
$message = "Individual";
         //header('location:Individual/EditLoginDetails.php');  

    }
    else if($typ == "Builder")
    {
    $message = "Builder";

        //header('location:Builder/ManageProjects.php'); 
    }



    }
   else
    { 


    header('HTTP/1.0 403 Forbidden');
echo "wrong username or password";
    }


    echo json_encode(array('error' => $error, 'message' => $message, 'redirect' => $redirect));
//}
?>
contentType: "application/json; charset=utf-8",