skip to Main Content

Im new to using ajax and I have another post here about my code and they said it was correct.
However Im still facing issues

My code:

body[circle.id] = {id: currentid-1, x: event.offsetX, y: event.offsetY};

// Ajax 
for(let i = 0;i < body.length;i++){
    $.ajax({                    
        url: 'get.php',     
        type: 'post', 
        data : {
            data: body[i],
          },
        dataType: 'json',                   
    });
}

The error:
[Error][1]

3

Answers


  1. According to the error image you have posted, The error says that the method only accepts the GET request but you are trying to make POST request in your AJAX method, Change your request type to GET like this,

    $.ajax({                    
      url: 'get.php',     
      type: 'get', 
      data : {
        data: body[i],
      },
      dataType: 'json',                   
    });
    
    Login or Signup to reply.
  2. I cannot comment.

    From the title I guess you are using Laravel.

    I see you are hitting the file directly, but looks like you are showing only half the setup. In case Laravel.
    What is the route setup?
    And if the setup is like Route::get try Route::any.
    How are you debugging the issue? Do you have any logs?
    Can you check the logs of “web server”?
    Either artisan serve or php -S should give at least some hints what your ajax is hitting.

    Login or Signup to reply.
  3. I fixed it.The problem was in url and routes

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search