我尝试使用 ajax 通过 JSON 显示一些数据,但是由于某种原因,当我提交表单时我没有得到任何结果,有什么建议吗?..
项目视图.php
<form id="formProjectsRepSearch" action="controller.php" method="post" onsubmit="searchFormProjectsRep();
return false">
<label>Project Name </label>
<input name="terbusqueda" id="term" type="text">
<button id="btnBuscar">Search</button>
<input type="hidden" name="search" value="go">
</form>
<div id="ajaxProjectsRep">
</div>
控制器.php
if (isset($_POST["search"]) && $_POST["search"] == "go"){
$name = $_POST['terbusqueda'];
$project = new Project();
$pro = $project->get_project($name);
$serv = $project->get_project_service_by_id($pro);
echo json_encode($serv);
}
require_once("../views/project_view.php");
JS
function searchFormProjectsRep() {
var $form = $('#formProjectsRepSearch');
$.ajax({
url: $form.attr('action'),
data: $form.serialize(),
type:'POST',
success: function (resp) {
var resp_object = $.parseJSON(resp);
$("#ajaxProjectsRep").html(resp_object.service);
},
dataType: "json"
});
}