简体   繁体   中英

Trouble accessing the value echoed from PHP file via JQuery and Javascript

I am having a frustrating amount of trouble with accessing the value echoed from my PHP file. I've looked at plenty, plenty, plenty of search results, but surprisingly still can't see what is wrong with my very simple code. My PHP file is very short (it's suppose to be way more complicated but I had to downgrade it to something very simple in attempt to get it to work): findjson.php

<?php
    echo "noise.json";
?>

My javascript file is:

$(document).ready(function(){
    $.get('findjson.php', function(data) {  
        alert(data); //uncomment this for debug
        $('#showdata').html("<p>item1="+ data + "</p>");
    });
});

but my code treats data as the whole php code (including the php tags) (I want it to be just "noise.json"). I've read that a possible issue may be call backs, but I think I implemented them. From reading online, it seemed that data would be the value that is being echoed from php?

First, for jquery $.get, you can set the data type to "json". Secondly, what happens if you browse to findjson.php with a browser? If you're getting the whole script including the php tags, you may not have your web server configured to parse PHP yet.

Is PHP installed in the server where you are hosting your "findjson.php"? If it is not, your jquery will not handle it any differently from a text file and reads and gets the contents of the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM