duanhui3759 2011-04-20 20:21
浏览 46
已采纳

too long

i took some interest in this script http://www.9lessons.info/2009/06/comment-system-with-jquery-ajax-and-php.html

and i see that the ajax calls commentajax.php.

what i want to do is to ignore that php, because i want to post to a json file and then get the response from the same file.

my server will use POST or PUT to put the data in the database, so there is no need for me to use php, just the syntax is killing me :)

i want to use :

$.ajax({
type: "POST",
url: "http://www.xxx.com/json",
data: dataString,
cache: false,
success: function(html){
    $("ol#update").append(html);
    $("ol#update li:last").fadeIn("slow");
    document.getElementById('comment').value='';
    $("#name").focus();
    $("#flash").hide();
}
});

but then how would the commentajax.php look like? maybe replace the php with :

$.getJSON('http://www.xxx.com/json' , function(data) { ... });

any idea helps Thanks.

edit1: i have the server-side script in place

  • 写回答

2条回答 默认 最新

  • duanqian8867 2011-04-20 20:57
    关注

    If you have the server side scripting set up already, then what is the question again?

    If you're asking how to handle the ajax call, then it's mostly a matter of looping through the JSON that you get back, and applying those values to the site in some manner. Pseudo code:

    $.getJSON('http://www.xxx.com/json' , function(data) { 
     for(i=0; i<data.comment.length; i++) {
       $(".commentTitle").html(data.comment[i].title);
       $(".commentBody").html(data.comment[i].text);
     }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?