簡體   English   中英

$ .get jquery函數返回完整的html頁面,而不是數據中的json

[英]$.get jquery function is returning a full html page instead of json in data

我正在開發一個Web應用程序,並且使用php作為服務器端語言,它返回JSON數據,這是返回JSON數據的PHP腳本:

<?php
require_once "connection.php";

if (isset($_GET['take'])) {

    $res = $conn->query('select * from pas where service=1');

}

if ($res->num_rows > 0) {
    $arr = array();
    while ($row = $res->fetch_assoc()) {
        array_push($arr, $row);
    }
    header("Content-type: application/json");
    echo json_encode($arr);
}

javascripte代碼是:

$.get('../controllers/sap.php?take=1', function(data) {
    console.log(data); //printing the result here
    console.log(data);
});

盡管昨天它在工作,但該PHP頁面是返回的結果...。

響應

我發現了問題,我是從intelliJDea IDE在與wamp服務器不同的端口上運行該應用程序的,而php在該端口上卻不起作用,但是當我從wamp服務器運行該應用程序時,它就起作用了,因為php浪費了該解決方案永遠無法運行一個PHP相關的應用程序,從任何一天的一天ID :)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM