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条)

报告相同问题?

悬赏问题

  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法