0

我正在尝试将使用 GET 的 ajax 调用转换为使用 POST 的调用。这是与GET. 将类型更改为POST不起作用。是数据字符串格式的问题吗?

 $.ajax({
    //type: "GET",  //works
    type: "POST",   // Does Not Work
    url: "/cgi-bin/my_perl.pl", // URL of the Perl script
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    //data format: "sid=" + sid + "&comments=" + comments,
    data: data_string,
    error: function(XMLHttpRequest, textStatus, errorThrown) { 
                            alert('AJAX Error');
    }, // error 
    // script call was successful 
    // data contains the JSON values returned by the Perl script 
    success: function(data){
            if(data.success) {
                    alert(data.success);
            }
            else if(data.error!=0) {
                    alert('We failed');
    } //else
    } // success
  }); // ajax
4

0 回答 0