title: How do I access Laravel API via Ajax
body: <p>I am trying to access an custom API built with Laravel using a Mobile Apps but getting a 404 Error. I have tried some of the solutions listed on this website but to no avail.</p>
  
  <p>I am using an Ajax request to fetch data like this</p>
  
  <pre><code>$.ajax({
  
             type:'POST',
             url: 'http://192.1**.**.**/mysite/api/v1/details',
             data: {id:id},
             dataType:"json",
             success: function(data)          
              {
                  alert(data);
                  var comment='';
  
                  for(var i = 0; i &lt; data.length; i++) {
                      comment = data[i];
                  }
  
              if (comment.userid){
  
                  Notification('Login Successful');// display success
  
                  setTimeout(function(){ window.location.assign('main.html'); },2000);
  
              }
              else if (comment.error){
  
                  Notification(comment.error);// display error
  
              }
  
        },
        error: function(jqXHR, exception) {
  
               if (jqXHR.status === 0) {
  
                  alert("Not connected. Verify Network.");//show error
  
              } else if (jqXHR.status == 404) {
  
                  alert("Requested page not found. [404]");//show error
  
              } else if (jqXHR.status == 500) {
  
                  alert("Internal Server Error [500].");//show error
  
              } else if (exception === 'parsererror') {
  
                  alert("Requested JSON parse failed.");//show error
  
              } else if (exception === 'timeout') {
  
                 alert("Time out error.");//show error
  
              } else if (exception === 'abort') {
  
                  alert( "Ajax request aborted.");//show error
  
              } else {
  
                  alert("Uncaught Error.\n" + jqXHR.responseText);//show error
              }
  
          }
  });
  </code></pre>
  
  <p>I also tried changing the URL to something like this as suggested by somebody but still don't work.</p>
  
  <pre><code>url: 'http://192.1**.**.**/mysite/public/index.php/api/v1/details'
  </code></pre>
  
  <p><strong>ROUTE</strong></p>
  
  <pre><code>Route::group(array('prefix' =&gt; 'api/v1', 'before' =&gt; 'auth.basic'), function()
      {
          Route::resource('users', 'UsersController');
          Route::resource('details', 'DetailsController');
      });
  </code></pre>
  
  <p>Please I am stuck badly, I need detail help.</p>