如何在PHP中使用noty master动态

时间:2016-02-19 17:45:35

标签: javascript php jquery ajax

我通过AJAX传递查询并尝试在noty-master jquery插件中获取数据。

HTML

<!DOCTYPE html>
 <html lang="en">
 <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Using with Buttons</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="demonstration of some noty capabilities">

<link href='http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic&amp;subset=latin,latin-ext,cyrillic' rel='stylesheet' type='text/css'>
<style type="text/css">

    html {
        height: 100%;
        width: 100%;
    }

    body {
        font-family: 'PT Sans', Tahoma, Arial, serif;
        line-height: 13px
    }

</style>

<link rel="stylesheet" type="text/css" href="buttons.css"/>

 </head>
 <body>

 <div class="container">

  <div id="customContainer"></div>

 </div>


<script src="noty-master/demo/jquery-1.7.2.min.js"></script>
<!-- noty -->
<script type="text/javascript" src="packaged/jquery.noty.packaged.js">        </script>
 <script type="text/javascript">
      function display(){
      //e.preventDefault();

      datastring = '2016-02-19';

           $.ajax({
            url: "bootajax.php",
            data: datastring,
            type:"POST"
        }).done(function(info) {    
            var data = jQuery.parseJSON(info);
            console.log(info);
            generate(data[0].fname, data[0].comment);

        });
}


 function generate(layout, name, comment) {
    var n = noty({
        text        : name+' : '+comment,
        type        : 'alert',
        dismissQueue: true,
        layout      : layout,        
        theme       : 'defaultTheme',
        buttons     : [
                 {addClass: 'btn btn-primary', text: 'Comment', onClick: function ($noty) {
                   $noty.close();
                   noty({dismissQueue: true, force: true, layout: layout, theme: 'defaultTheme', text: 'You clicked "Comment" button', type: 'success'});
            }
            },
            {addClass: 'btn btn-danger', text: 'Dismiss', onClick: function ($noty) {
                $noty.close();
                noty({dismissQueue: true, force: true, layout: layout, theme: 'defaultTheme', text: 'You clicked "Dismiss" button', type: 'error'});
            }
            }
        ]
    });
    console.log('html: ' + n.options.id);
}

function generateAll() {
    generate('centerRight');

}

$(document).ready(function () {

    generateAll();
    display();
});
</script>
</body> 
</html>

AJAX

 <?php session_start();


 $companydata = $_SESSION['company'];

$idCompany = $companydata['id'];
$fnameCompany = $companydata['fname'];
$lnameCompany = $companydata['lname'];
$password = $companydata['password'];

$dbhost = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "gym";
$time = date('Y-m-d');

$conn = mysqli_connect($dbhost, $dbusername, $dbpassword, $dbname) or die ("could not connect");

 $sql = "SELECT * from inquiry where callback = '2016-02-19'";   

 $result = mysqli_query($conn, $sql);

 $row = mysqli_fetch_all($result, MYSQLI_ASSOC);

 echo json_encode($row);
?>

我使用过JSON并尝试传递数据,但其显示:

  

未捕获的错误,无法准备好属性&#39;选项&#39;未定义的

请帮忙。

0 个答案:

没有答案