Guest User

Untitled

a guest
Oct 16th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. <html>
  2. <head>
  3. <link rel="stylesheet" href="css/myStyles.css">
  4. <link rel="stylesheet" href="css/bootstrap.min.css">
  5. <link rel="stylesheet" href="css/bootstrap-theme.min.css">
  6. <script src="js/bootstrap.min.js"></script>
  7. <script src="js/jquery-3.0.0.min.js"></script>
  8.  
  9. <?php
  10. include "header.html";
  11. include "left_menu.php";
  12. ?>
  13. </head>
  14. <body>
  15. <div align="center">
  16.  
  17. <form id="form" action="" method="post">
  18. <input type="text" name="model"><br>
  19. <input id="submit" type="button" name="submit" value="submit">
  20. </form>
  21. </div>
  22. <div id="result"></div>
  23. <script language="JavaScript">
  24. var input = document.getElementsByName("model");
  25. input=input[0].value;
  26. // click on button submit
  27. $("#submit").on('click', function(){
  28. // send ajax
  29. $.ajax({
  30.  
  31. type : "POST", // type of action POST || GET
  32. dataType : 'json', // data type
  33. url: 'php/search_script.php', // url where to submit the request
  34. data : {model:input}, // post data || get data
  35. success : function() {
  36. var name = <?php echo $json?>
  37. console.log(name);
  38. },
  39. error: function(xhr, resp, text) {
  40. console.log(xhr, resp, text);
  41. }
  42. })
  43. });
  44.  
  45. </script>
  46. </body>
  47. <?php
  48. include "footer.php";
  49. ?>
  50. </html>
  51.  
  52. <?php
  53. $data=array();
  54. header('Content-type: application/json');
  55. $connect = pg_connect("host=localhost port=5432 dbname=weapon user=arakul password=1111") or die("dsfsdfg");
  56. pg_set_client_encoding($connect,UTF-8);
  57. $post = $_POST['model'];
  58. echo $post;
  59. $query = sprintf("SELECT description from model where title = 'M4'");
  60. $result = pg_query($connect, $query) or die(pg_last_error($result));
  61. while($row=pg_fetch_assoc($result)) {
  62. $data[] = array($row["name"]);
  63. }
  64.  
  65. $json=json_encode($data)
  66.  
  67. echo $json;
  68.  
  69. Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…} "parsererror" SyntaxError: Unexpected token < in JSON at position 0
  70. at parse (<anonymous>)
  71. at Nb (jquery-3.0.0.min.js:4)
  72. at A (jquery-3.0.0.min.js:4)
  73. at XMLHttpRequest.<anonymous> (jquery-3.0.0.min.js:4)
Add Comment
Please, Sign In to add comment