Submit form (django-form) with Imagefield via Jquery/Ajax Post?

后端 未结 2 430
攒了一身酷
攒了一身酷 2020-12-22 06:12

Im having some problems submitting a form (Django-form) with a imagefield with Jquery/ajax POST. Im getting back \"Field required\" validation errors on the imagefield..

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-22 07:03

    Sounds like you've a required attribute on the image field and you're not stopping default behaviour for click function.

    $('#imageupload').on('click', function(e) { 
        e.preventDefault();
    

    Bit hard to tell without your HTML code... You should ideally use a form with an id then target that element to bind to the 'submit' event so Enter key and touch events are also handled by the same code.

    $('#imageform').on('submit', function (e){ e.preventDefault() // other code here } 
    

    See also: Ajax Upload image

提交回复
热议问题