0

我将以下 Post 请求发送到远程 apache 服务器,托管一个小型 php 脚本:

邮政:

var request = $.ajax({
    type: 'POST',
    url: 'http://my.server.on.port/mmm.php',
    data: { abc: "abcdefghijklmnopqrstuvwxyz" } })
    .done(function(data) { alert("success :"+data.slice(0, 100)); });

request.fail(function(jqXHR, textStatus) {
    alert( "Request failed: " + request.reponseText + " " + request.status  +" " + request.statusText +" " +request.responseText  );
});

mmm.php 脚本:

<?php echo json_encode(array("first"=>"XXXXX","last"=>"YYYYY")); ?>

httpd.conf:

ServerName my.server.on.port
DocumentRoot "/var/www/html"

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

NameVirtualHost "my.server.on.port"
Listen 80

<VirtualHost *:80>
    DocumentRoot "/var/www/html/QR/tst"
    ServerName "my.server.on.port:80"

    <Directory "/var/www/html/QR/tst">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>

    <Directory "/var/www/html/QR/tst/css/smoothness">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
    <Directory "/var/www/html/QR/tst/development-bundle">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
    <Directory "/var/www/html/QR/tst/development-bundle/ui">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
    <Directory "/var/www/html/QR/tst/development-bundle/demos">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>

</VirtualHost>

来自服务器的回复是 304。所有文件都有 755 权限。没有 idia 如何解决这个问题。谢谢!

HTTP/1.1 304 Not Modified
Date: Sat, 21 Jul 2012 08:45:38 GMT
Server: Apache/2.2.22 (Fedora)
Connection: close
ETag: "c0744-f7a-4c553071e0d4e"

这是带有错误的警报: 警报

4

2 回答 2

1

试试这个ajax请求

var request = $.ajax({
type:"post",
url:"http://my.server.on.port/mmm.php",
data:"abc=abcd",
//success:function(data){ console.log("success "+data); },
//error:function(data){console.error("error "+data;},
statusCode:{
200:function(){console.log("got 200")},
304:function(){console.log("got 304")},
404:function(){console.error("got 404")}},
isModified:function(){console.log("Something was modified");}
}).responseText;
// i haven't used .done .fail but i believe the code below would work.
request.done(function(data){ console.log("got response "+data); }); 
request.fail(function(jqXHR,textStatus){ 
console.log("Request Failed\n"+"object dump :"+console.log(jqXHR)+"\n"+"textStatus :"+textStatus); 
}); // changed according to the example from jquery site.
于 2012-07-21T09:38:40.537 回答
0

这对我有用(在 chrome 和 IE 上测试):

 var request = $.ajax({
     type: "post",
     url: "mmm.php",
     data:"abcdefghijklmnopqrstuvwxyz",
     success:function(data){ alert("success: " +JSON.stringify(data)); },
     error:function(data){ alert("error "+JSON.stringify(data)); },
     statusCode:{
          200:function(){alert("200 OK");},
          304:function(){alert("304 Not Modified");},
          404:function(){alert("404 No Found");}},
     isModified:function(){alert("Something was modified");}
 });

感谢任何帮助过的人!

于 2012-07-23T06:59:08.693 回答