如何在jquery.ajax()方法中使用dataType设置来接收mysql数据库的获取对象?

时间:2018-02-18 17:12:50

标签: jquery mysql sql json ajax

抱歉,我拉丁语所以我的英语不好,我试图获取一个mysql数据库的获取对象,但我以前从未使用$.ajax()方法和{{{{1}的结果1}}是alert(response.word),有人可以帮助我解决这个问题并告诉我undefined设置的工作原理吗?因为JQuery Documentation API中的信息对我来说不是很明显。在此先感谢...!

indexScript.js

dataType: "json"

的search.php

dictionarySearchForm.on("submit", function(e){
   e.preventDefault();
   $.ajax({
      url: "dictionary/search.php",
      type: "get",
      dataType: "json",
      data: { wordToSearch: wordToSearch.val() },
      success: function(response){
         alert(response.word);
      },
      error: function(){
         alert("Fail...!");
      }
   });
});

connection.php

<?php

if(isset($_GET["wordToSearch"])){

    include_once("../connection/connection.php");

    $word = $_GET["wordToSearch"];

    $connection = Connection::getConnection();
    $query = "select * from english_dictionary_table where word like ':wordMarker%'";
    $result = $connection->prepare($query);
    $result->execute(array(":wordMarker" => $word));
    $arrayRegisters = $result->fetchAll(PDO::FETCH_OBJ);

    echo(json_encode($arrayRegisters));

}

?>

0 个答案:

没有答案