2015-11-04 80 views
-3

好了,所以我说我从WAMP本地服务器上读取这个txt文件,AJAX jQuery的成功,但没有改变

我修改这段文字,并尝试将其发送回文件

ajax请求会触发成功功能,但文件不会更改,有什么想法?感谢

代码:

var customCss = ""; 
var customCssPath = "http://localhost:8081/userThemer/styles/custom.css"; 
var newStyle ="newwww"; 
    $.ajax({ 
     type: 'POST', 
     url: customCssPath,//url of receiver file on server 
     data: newStyle, //your data 
     success: function() { 
      console.log("YAY !"); 
     }, 
     error: function() { 
      console.log(":'("); 
     }, 
     dataType: "text" //text/json... 
    }); 
+3

您正在将数据发布到CSS文件...是吗?检查控制台的网络选项卡以查看请求的确切状态。 –

+1

究竟是什么*处理请求服务器端? Web服务器可能会成功返回任何HTTP动词的CSS文件(在本例中为POST),但这并不意味着它实际上对您发布的数据执行任何操作*。你有什么机制来实际使用服务器上发布的数据? – David

回答

0

方才明白$.ajax

$.ajax({ 
     url: 'xyz.php',  // url of receiver file on server    
     type: 'POST', // send method, either POST or GET   
     data: data,  // data to be sent to $url 
     dataType: 'text', // tells what kind of respnse you get 
     success: function (response) { // success call with response 
      console.log("WOW! your respnose is" + response); 
     }, 
     error: function() { // error 
      console.log("ERROR Occured!!"); 
     } 
    }); 

更新:

在你recevier文件(如我提到xyz.php),echo您期望的响应,如:

<?php 
    echo 'this is a response from xyz.php file'; 
?> 
+0

它回应我的原始文件文本 –

+0

查看更新的答案@JosephKhella – SHAZ

1
success: function (data) { 
console.log(data); 
console.log("YAY !"); 
}, 

请尝试这种方式。你可以得到这些数据。

+0

我想POST数据没有GET' –

+0

很抱歉,如果您尝试使用POST,数据的回应是什么? – dinesh