2015-11-04 69 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