Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
没有php的jquery消息系统如何实现?_Php_Jquery_Ajax_Post_Put - Fatal编程技术网

没有php的jquery消息系统如何实现?

没有php的jquery消息系统如何实现?,php,jquery,ajax,post,put,Php,Jquery,Ajax,Post,Put,我对这个剧本感兴趣 我看到ajax调用了commentajax.php 我想做的是忽略这个php,因为我想发布到一个json文件,然后从同一个文件获得响应 我的服务器将使用POST或PUT将数据放入数据库中,因此我不需要使用php,只是语法让我头疼:) 我想使用: $.ajax({ type: "POST", url: "http://www.xxx.com/json", data: dataString, cache: false, success: function(html){ $

我对这个剧本感兴趣

我看到ajax调用了
commentajax.php

我想做的是忽略这个php,因为我想发布到一个json文件,然后从同一个文件获得响应

我的服务器将使用
POST
PUT
将数据放入数据库中,因此我不需要使用php,只是语法让我头疼:)

我想使用:

$.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();
}
});
但是,
commentajax.php
会是什么样子呢? 可能用以下内容替换php:

$.getJSON('http://www.xxx.com/json' , function(data) { ... });
有什么好主意吗 谢谢


edit1:
如果我正确阅读了以下内容,我已经准备好了服务器端脚本

because i want to post to a json file and then get the response from the same file.
您需要一些服务器端脚本来“发布”到json文件。你是如何把数据输入文件的


您可以从服务器“读取”数据文件,这不是问题,而是将数据放入需要服务器端脚本的文件中。

如果您已经设置了服务器端脚本,那么问题是什么

如果您询问如何处理ajax调用,那么主要是通过返回的JSON循环,并以某种方式将这些值应用到站点。伪代码:

$.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);
 }
});
$.getJSON('http://www.xxx.com/json,函数(数据){

对于(i=0;i您确实意识到,如果没有一些服务器端代码,这是绝对不可能做到的,对吗?好吧,为什么不呢。您可以将Web服务器设置为允许
PUT
向静态
json
文件写入请求。问题是您无法抵御恶意客户端。您的jQuery代码需要获取该文件,更新它,然后n将其放回json文件中。技术上可行,但有用性仍有争议。对,我现在使用
PUT
来更新我的数据库,我只是对这个脚本有点困惑。我建议您使用一些带有http接口的数据库(如MongoDB、CouchDB)对于它,而不是文件。从Js的角度来看,它的工作原理是一样的,它将在一开始就解决很多问题。而且已经有了用于它的Js库。我已经准备好了服务器端脚本,我只需要知道Js的wright语法是什么