1

I have a route like this --

Route::put('avote', 'voteController@avote')->middleware('auth'); 

I want to access this route from a ajax send request.
When i use this code --

$data = {/* some data here */}; $.post("/avote", $data, function(result) { $('#avote h2').html(result); $('#avote a span').css('color', 'orange'); $('#avote a span').unwrap(); }); 

I get an error method not allowed. I know that it is the problem of method I used (used post not put)

I question is, is there any way i can get the information from /avote using ajax or any other scripts?

Please dont suggest me to change the route request from put to post or Any other way to protect the /avote route

I used Route::put() beacuse i have a database update function in the route controller

1 Answer 1

2

Move to $.ajax() function instead of $.post and provide method (type) property:

$.ajax({ url: "/avote", data: $data, method: "PUT", // or type: "PUT", if your jquery version is prior to 1.9 success: function(result) { $('#avote h2').html(result); $('#avote a span').css('color', 'orange'); $('#avote a span').unwrap(); } }); 
Sign up to request clarification or add additional context in comments.

6 Comments

now it is working correctly. Thanks, but now the problem is success function not working
Clarify please, what does it mean. Any errors in console?
no success message or anything. The request is working correctly but there is no response
See raw response, it nothing is outputted - check your route
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.