AJAX jQuery成功,但没有改变

AJAX jQuery Success but no change

本文关键字:改变 jQuery 成功 AJAX      更新时间:2023-09-26

好的,所以我得到了这个txt文件,我正在从wamp本地服务器读取

我对此文本进行了更改,并尝试将其发送回文件

ajax请求触发了success函数,但文件没有更改,有什么想法吗?感谢

代码:

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...
    });
success: function (data) {
console.log(data);
console.log("YAY !");
},

请试试这条路。你可以得到数据。

只需理解$.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';
 ?>