Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

jquery - can getJSON() be used for php?

This is the JQuery code loaded over click but the callback function isn't working:

$.getJSON("load_img.php", {"id":"start"} , function(json){
     alert(json);
});

PHP code gives me this output:

[
    {"img_name":"shiva.jpg","img_id":"1"}, 
    {"img_name":"shiva.jpg","img_id":"2"},
    {"img_name":"Recoverd_jpg_file(4).jpg","img_id":"3"}, 
    {"img_name":"Recoverd_jpg_file(542).jpg","img_id":"4"}
]

I cannot load any PHP pages from getJSON() function...i downloaded sample source code from [here][1]

[1]: http://www.sitepoint.com/ajaxjquery-getjson-simple/ and have run it on browser but it doesnt work still... any help would be much appreciated!!!Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I got my answer today...no <html> tags should be included in the code to be outputted... it should only contain starting and ending php tags i.e.

<?php
//your code or codes
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...