Django Ajax Form submit wrongly redirect to another page

前端 未结 2 490
悲哀的现实
悲哀的现实 2021-01-15 18:07

When I use ajax to submit a comment form in Django,the page will redirect to a blank page shows me the success data:

{\"status\":\"success\", \"msg\":\"添加成功\         


        
2条回答
  •  灰色年华
    2021-01-15 18:29

    Finally I made it!Thanks Lord!Very excited!

    I have Three major issues in my previous code.

    First:Since the ajax will post the news_pk to the view update_comment,so I don't need add news_pk in this view's url and template(in the url of

    tag and the url in the ajax),so I removed them,or the data will still pass through Form but not ajax.

    Second:My binding is incorrect,I have the click handler on the form it should be a submit handler. If I was binding it to a button then I'd use click a handler.Ajax not work in Django post But for this part I'm still a some confused,between the button summit way and form submit way.

    The third issue is I mistaked 'comments' and 'comment'.'comment' is the name attribute of

    I really appreciate everyone's reply!With your reply I figured out these issue step by step!

提交回复
热议问题