使用Post Call的Ajax

时间:2013-06-20 16:38:56

标签: ajax post get

我正在尝试使用POST将使用GET的ajax调用转换为一个。 这是与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

0 个答案:

没有答案