Question

I shoot the following Post request to a remote apache server,hosting a small php script:

The POST:

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 script:

<?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>

The reply from the server is 304. all files has 755 permission. No idia how to solve this. thanx!

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"

this is the alert with the error: alert

Was it helpful?

Solution 2

This Works for me (tested on chrome and 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");}
 });

Thanks to anyone that helped!

OTHER TIPS

try this ajax request

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top