javascript - Ajax function not receiving response from server -


essentially working uploader (dropzone.js) , incorporating website. adding files server works fine, having trouble deleting them. javascript:

$(document).ready(function () {     dropzone.autodiscover = true;     $("#dzupload").dropzone({         url: "uploadhandler.ashx",         addremovelinks: true,         success: function (file, response) {             file.previewelement.classlist.add("dz-success");             console.log("successfully uploaded: " + file.name);         },         error: function (file, response) {             file.previewelement.classlist.add("dz-error");         },         init: function () {             var dzupload = this;             this.on("removedfile", function (file) {                 $.ajax({                     type: "post",                     url: "uploadhandler.ashx/deletefile",                     data: { filename: file.name },                     datatype: "json",                     success: function (repsonse) {                         if (data == "success") {                             alert("successfully deleted.");                             this.removefile(file);                         }                         else {                             alert("error deleting file.");                             this.removefile(file);                         }                     }                 });             });         }      }); }); 

and code deletefile function on server-side handler:

    <system.web.services.webmethod()> _ public function deletefile(filename string) string     try         dim yes string = "success"         system.io.file.delete(path.combine(httpcontext.current.server.mappath("~/serverfiles/"), filename))         return yes     catch ex exception         dim no string = "failure"         return no     end try end function 

what should happening: when remove link clicked on uploaded file, client sends post through ajax server. server deletes file off disk , sends message client saying success.

this first time using ajax, happening? why isn't message being sent?

edit: when change datatype: "json" test reeive following error:

uncaught referenceerror: data not defined $.ajax.success @ fileuploader.aspx:31 

line 31 this: if (data == "success") {

so little better i'm still not sure how proceed.

declare web method shared (static) e.g.

    public shared function deletefile(filename string) string 

and modify ajax call to:

    var data = { filename: file.name }     $.ajax({          method: "post",          url: "uploadhandler.ashx/deletefile",          data: json.stringify(data),          datatype: "json",          contenttype: "application/json; charset=utf-8",          success: function (repsonse) {              if (data == "success") {                  alert("successfully deleted.");                  this.removefile(file);              }              else {                  alert("error deleting file.");                  this.removefile(file);              }          }     }); 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -