JQuery AJAX call to the php SLIM framework calls the error function, without no error message? -


i have server side slim code:

require 'slim/slim.php';  $app = new slim(); //$app->config('debug', true); $app->get('/hello', 'hello'); //$app->post('/addconsultant', 'addconsultant'); $app->run();  function hello() {     echo '{"hello": ' . json_encode("merp") . '}'; } 

pretty bare bones right? mean 1 single get.

now, have client side javascript code:

var rooturl = "http://somabsolutions.se/dev/index.php/";  $('#btnhello').click(function() {     $.ajax({         type: 'get',         url: rooturl + '/hello',         datatype: "text json",         success: function(data){             alert("something " + data);         },         error: ajaxfailed     });      return false; });  function ajaxfailed(xmlhttprequest, textstatus, errorthrown) {     alert("xmlhttprequest=" + xmlhttprequest.responsetext + "\ntextstatus=" + textstatus     + "\nerrorthrown=" + errorthrown); } 

also pretty easy.

i have html stuff, holds button bound ajax call jquery:

<!doctype html>     <html>         <head>             <title>                 backend test             </title>         </head>         <body>             <form id="testform">                  <button id="btnhello">hello world</button>              </form>             <script src="javascript/jquery-1.7.2.min.js"></script>             <script src="javascript/main.js"></script>         </body>      </html> 

this stuff, used work, until today, when alien reason stopped doing so!

see, works, right?

but every time press html button, ajax thinks call fails , redirects me error function, fails provide me blank error messages.

what wrong this? worked fine days ago!

your problem might root url ends / , have in beginning of added url /hello again (so url root//hello requested) or there problem datatype: "text json". used datatype: "json" worked me.

also (but it's formatting thing) make line bit more php style: ( know it's more code, think it's easier read , looks more php... :d)

echo '{"hello": ' . json_encode("merp") . '}';

if change to:

echo json_encode( array("hello" => "merp") );


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -