简体   繁体   中英

jquery $post 405 (Method Not Allowed) to ASP.NET Folder

I am trying to do a $post call to an ASP.NET Folder that is inside my ASP.NET Project) and I keep getting these errors:

TypeError: $http.post(...).success is not a function

http://localhost/Uploads 405 (Method Not Allowed)

Here is my code:

var fd = new FormData();
        fd.append('file', file);
        console.log(file);
        console.log(fd);
        $http.post(uploadUrl, fd, {
            transformRequest: angular.identity,
            headers: { 'Content-Type': undefined }
        })
        .success(function () {
        })
        .error(function () {
        });

After doing some debugging, the file is not empty (its from input type file) uploadUrl is not empty (its http://localhost/Uploads ) however my FormData is empty. What am I doing wrong? I am trying to upload a file via jquery to an ASP.NET Folder called Uploads.

first, you need to setupa a Controller Action that takes a ViewModel parameter. Inside that action you'll have to take care of the file saving into disk etc. And for submitting or calling the action to upload file, take a look at this answer here . setup a ajax request with jQuery and setup appropriate Content-Type for it to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM