kamish's avatar

the server responded with a status of 405

Hi, I built application that allows updating and uploading posts. Post-update via ajax I do, but for some reason I get an error of "POST 405 (Method not allowed)".

Here's the code:

$("form#updata_post").submit(function(event){
          
        event.preventDefault();
      

    tinyMCE.triggerSave();

 text_body = $("#body").val();

 $("#all_body").val(text_body);





          var formData = new FormData($(this)[0]);

        $.ajax({
            url: "{{Request::root(); }}/updata_post/",
            dataType: "json",
            type: "POST",
            data: formData,
           success: function(data) { 

               $(".info").hide().find("ul").empty(); 

        
             if (!data.success) {


              $.each(data.errors, function(index, error){

                 $(".info").append("<ul>" + error + "</ul>"); 

              });

              $(".info").slideDown( "slow" );


           

        }

           else {

          window.location = "{{URL::to('posts')}}";



           }


          }, 

            cache: false,
            contentType: false,
            processData: false
        });

    });



</script>


-----------------------


public function updata_post() {
       $validator = Validator::make(Input::all(), postmodel::$rules);
        if ($validator->passes()) {
     
       $id = Input::get('id');
        $post =  postmodel::find($id);
              $img_file = Input::file('file');
           if (!empty($img_file)) {
       $image = Input::file('file');
       $imagename = rand(1,99999).$image->getClientOriginalName();
        $upload = $image->move(public_path() . "/img/",$imagename);
        $post->main_img = $imagename;
        }
       
       $post->description = Input::get('description');
       
       $post->title = Input::get('title');
       $post->all_files = Input::get('all_files');
       $slug = Input::get('slug');
       if (!empty($slug)) {
        $post->slug = str_replace(" ", "-", Input::get('slug'));
       }
       else {
        $post->slug = str_replace(" ", "-", Input::get('title'));
       }
       $post->body = Input::get('text_body');
       $post->name = Input::get('name');
       $post->section = Input::get('section');
        
       $post->save();
       //return Redirect::to('posts');
       return Response::json(['success' => true]);
      }
        else {
       return Response::json(['success' => false, 'errors' => $validator->messages()->toArray()]);
       
    }


0 likes
1 reply

Please or to participate in this conversation.