Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
带参数的jquery ajax post_Jquery_Ajax_Post - Fatal编程技术网

带参数的jquery ajax post

带参数的jquery ajax post,jquery,ajax,post,Jquery,Ajax,Post,我需要使用JQuery的$ajax功能上传文件,除了上传文件外,我还想知道该文件上传到哪个文件夹/目录。我尝试了以下方法,但无效: data = new FormData() data.append('csv', fileData) $.ajax cache: false contentType:false processData: false type: 'POST' dataType: 'script' url: '/api/upl

我需要使用JQuery的$ajax功能上传文件,除了上传文件外,我还想知道该文件上传到哪个文件夹/目录。我尝试了以下方法,但无效:

  data = new FormData()
  data.append('csv', fileData)
  $.ajax
    cache: false
    contentType:false
    processData: false
    type: 'POST'
    dataType: 'script'
    url: '/api/upload/'
    params: ['test']   <-- folder/directory i want to upload to
    data: data

    complete: (res) =>
      if not (res.status is 200)
        console.log(res.responseText)
        return false
      else
        return true

如何将额外的参数传递给ajax post?谢谢

您可以将附加参数添加到formData

data = new FormData()
data.append('csv', fileData)
data.append('path', 'my/path')

中没有名为
params
的选项尝试搜索更多信息,您会发现这很有用:
data = new FormData()
data.append('csv', fileData)
data.append('path', 'my/path')