Advertisement
Guest User

jq2

a guest
Nov 20th, 2013
1,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.49 KB | None | 0 0
  1. <?php
  2. // mysqli(хост, пользователь, пароль_пользователя, название_БД)
  3. $connect = new mysqli("localhost", "root", "", "managerarticle");
  4. $connect->query("SET NAMES 'utf8'");
  5. ?>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
  9. <title>Сайтик</title>
  10. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  11. <link href="layout/style.css" rel="stylesheet" type="text/css" />
  12. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
  13.  
  14. </head>
  15. <body>
  16. <div id="wrap">
  17.   <div id="header">
  18.     <div id="logo">Редактор статей по технологии Ajax</div>
  19.     <div id="nav">
  20.       <ul>
  21.         <li class="active"><a href="index.php">Главная страница</a></li>
  22.       </ul>
  23.     </div>
  24.     <div id="header-pic"> <img src="info/header-pics/index-header.jpg" alt="" /> </div>
  25.   </div>
  26.   <div id="content-wrap">
  27.     <div id="content">
  28.       <h1> Редактор товаров</h1>
  29.       <div>
  30.       Добавить товар:<br>
  31.       <input type="text" id="ids"  name="article_title_new"  placeholder="Название товара">
  32.       <input type="button" name="addArticle" value="Добавить новый товар"><br>
  33.       </div><br>
  34.       <table border="0" cellspacing="0" cellpadding="0">
  35.         <caption>
  36.         Товары
  37.         </caption>
  38.         <tr>
  39.           <th >Номер товара</th>
  40.           <th>Название</th>
  41.           <th>Редактирование</th>
  42.         </tr>
  43.       <?php
  44.         // достаем из базы данных ID и заголовок всех статей
  45.         $result = $connect->query("select article_id, article_title from article");
  46.           //определяем количество полученных записей
  47.           $colResult = $result->num_rows;
  48.  
  49.           if($colResult > 0)
  50.           {
  51.             for($i = 0; $i < $colResult; $i++)
  52.           {
  53.              $row = $result->fetch_object();
  54.                echo"<tr>";
  55.                echo "<td>".$row->article_id."</td>";
  56.                echo "<td>".$row->article_title."</td>";
  57.                echo "<td><center><input type='checkbox' name='delete_button[]' value='".$row->article_id."'></center></td>";
  58.                echo "</tr>";    
  59.             }
  60.           }
  61.         ?>
  62.       </table>
  63.  
  64.     </div>
  65.     <script  type="text/javascript" >
  66.   $(document).ready( function()
  67.   {
  68.    // обрабатываем событие нажатия на кнопку "Добавить новый товар"  
  69.    $('input[name=addArticle]').click(
  70.        function ()
  71.        {
  72.           var article_title = $('input[name=article_title_new]').val();
  73.           // отправляем AJAX запрос
  74.           $.ajax(
  75.              {
  76.                 type: "POST",
  77.                 url: "index.php",
  78.                 data: "article_title=" + article_title,
  79.                 success: function(response)
  80.                 {
  81.                    if(response == "OK")
  82.                    {
  83.                       alert("Товар " + article_title + " добавлен!");
  84.                       location.reload();
  85.                    }
  86.                    else
  87.                    alert("" + response);
  88.                 }
  89.              }
  90.              );
  91.        }
  92.     );
  93.   });
  94. </script>
  95.   </body>
  96.  </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement