Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax imageupload在本地工作,但在服务器上不工作_Ajax_Vb.net_Web Services_Webmethod_Image Upload - Fatal编程技术网

Ajax imageupload在本地工作,但在服务器上不工作

Ajax imageupload在本地工作,但在服务器上不工作,ajax,vb.net,web-services,webmethod,image-upload,Ajax,Vb.net,Web Services,Webmethod,Image Upload,我想在服务器上上传一个图像。我使用ajax和webmethod,当我在本地主机上运行代码时,它工作,但当我在服务器上上传它时,它不工作。 我想我的webmethod有一些问题,但我找不到 function savefile(location, files, method_name) { var data = new FormData(); var webmethod = "../WebService.asmx/" + method-name;

我想在服务器上上传一个图像。我使用ajax和webmethod,当我在本地主机上运行代码时,它工作,但当我在服务器上上传它时,它不工作。 我想我的webmethod有一些问题,但我找不到

    function savefile(location, files, method_name) {

        var data = new FormData();
        var webmethod = "../WebService.asmx/" + method-name;


        if (files.length > 0) {
            data.append("UploadedFile", files[0]);
            data.append("location", location);


        }

        var ajaxRequest = $.ajax({
            type: "POST",
            url: webmethod,
            enctype: 'multipart/form-data',
            contentType: false,
            processData: false,
            data: data


        });


    }


     <WebMethod(EnableSession:=True)> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
        Public Function savefile() As String
            Try

                Dim result As String = ""
                Dim pdf As String = ""
                If HttpContext.Current.Request.Files.AllKeys.Any() Then


                    Dim httpPostedFile = HttpContext.Current.Request.Files("UploadedFile")

                    If httpPostedFile IsNot Nothing Then

                        Dim location = HttpContext.Current.Request("location")
                        Dim extension As String = System.IO.Path.GetExtension(httpPostedFile.FileName)
                        Dim filename_widthout_extension As String = httpPostedFile.FileName.Substring(0, httpPostedFile.FileName.Length - extension.Length)
                        Dim file_name = httpPostedFile.FileName
                        Dim fileSavePath = System.IO.Path.Combine(Server.MapPath(HttpContext.Current.Request("location").ToString), filename_widthout_extension + postfix + extension)



                        result = (location + "/" + filename_widthout_extension + extension).ToString.Substring(2)

                        httpPostedFile.SaveAs(fileSavePath)
                        location = httpPostedFile.FileName
 End If
            Return ""

        Catch ex As Exception

        End Try
    End Function
函数保存文件(位置、文件、方法名称){
var data=new FormData();
var webmethod=“../WebService.asmx/”+方法名称;
如果(files.length>0){
data.append(“UploadedFile”,files[0]);
数据。追加(“位置”,位置);
}
var ajaxRequest=$.ajax({
类型:“POST”,
url:webmethod,
enctype:“多部分/表单数据”,
contentType:false,
processData:false,
数据:数据
});
}
_
公共函数savefile()作为字符串
尝试
将结果变暗为字符串=“”
Dim pdf As String=“”
如果是HttpContext.Current.Request.Files.AllKeys.Any(),则
Dim httpPostedFile=HttpContext.Current.Request.Files(“UploadedFile”)
如果httpPostedFile不是空的,那么
Dim location=HttpContext.Current.Request(“位置”)
Dim扩展名为String=System.IO.Path.GetExtension(httpPostedFile.FileName)
Dim filename\u widthout\u扩展名为String=httpPostedFile.filename.Substring(0,httpPostedFile.filename.Length-extension.Length)
Dim file_name=httpPostedFile.FileName
Dim fileSavePath=System.IO.Path.Combine(Server.MapPath(HttpContext.Current.Request(“location”).ToString),filename\u widthout\u扩展名+后缀+扩展名)
结果=(位置+“/”+filename\u widthout\u扩展名+扩展名)。ToString.Substring(2)
httpPostedFile.SaveAs(fileSavePath)
location=httpPostedFile.FileName
如果结束
返回“”
特例
结束尝试
端函数

您是否遇到异常?我怀疑将文件写入服务器上的目录可能存在权限问题No!我将MsgBox放在webmethod的开头,并注释webmethod的所有代码。我发现webmethod的代码没有运行。我在脚本代码中添加了一些警报,它们显示出来了。我注意到您正在通过
“./WebService.asmx/”
访问此方法,但您的页面的url是什么?如果页面和Web服务位于同一文件夹中,则不应指定
。/
部分(url是相对于页面而不是脚本的)错误,服务器代码中的MsgBox不会弹出,而是在服务中执行。(当然,如果您不在调试中)我已经用handler替换了webmethod,它工作得很好。但是我没有成功地使用webmethod。您是否遇到异常?我怀疑将文件写入服务器上的目录可能存在权限问题No!我将MsgBox放在webmethod的开头,并注释webmethod的所有代码。我发现webmethod的代码没有运行。我在脚本代码中添加了一些警报,它们显示出来了。我注意到您正在通过
“./WebService.asmx/”
访问此方法,但您的页面的url是什么?如果页面和Web服务位于同一文件夹中,则不应指定
。/
部分(url是相对于页面而不是脚本的)错误,服务器代码中的MsgBox不会弹出,而是在服务中执行。(当然,如果您不在调试中的话)我已经用handler替换了webmethod,它工作得很好。但是我没有成功地使用webmethod