javascript - Getting 400 (Bad Request) making a "POST" using ajax to a rails web site -


i've benn trying make "post" using ajax, keep getting "400 (bad request)". don't know if it's rails website or ajax request. rails it's simple scaffold:

 # post /events  # post /events.json def create  @event = event.new(event_params) respond_to |format|   if @event.save     format.html { redirect_to @event, notice: 'event created.' }     format.json { render :show, status: :created, location: @event }   else     format.html { render :new }     format.json { render json: @event.errors, status: 409 }   end end end   def event_params   params.require(:event).permit(:name, :consult, :description, :category, :likes) end 

and ajax i'm trying make work:

$("button").click(function () {          $.ajax({             url: 'http://localhost:3000/events',              type: 'post',             cache: true,             processdata: false,             contenttype: "application/json; charset=utf-8",             datatype: "json",             data: { event: {  name: "testname", consult: 72, description: "this test", category: "dance", likes: 23 } },             success: function (resp) {                  alert(resp);             }           }); 

please change

url: http://localhost:3000/events url: http://localhost:3000/events.json

then let me know result.

thanks


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -