Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.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
Javascript 如何将data.append与$this.attr()混合使用_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 如何将data.append与$this.attr()混合使用

Javascript 如何将data.append与$this.attr()混合使用,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我只是想学习如何在jQueryAjax中将data.append()与$this.attr()混合使用,因为我在php while循环中创建了表单,每个表单都有其唯一的名称。我有这个: var data = new FormData() data.append( 'photo', $( '#photo_' + $this.attr("name") + '_id' )[0].files[0] ), data.append( 'firstname', $( '#firstname_

我只是想学习如何在jQueryAjax中将data.append()与$this.attr()混合使用,因为我在php while循环中创建了表单,每个表单都有其唯一的名称。我有这个:

var data = new FormData()
    data.append( 'photo', $( '#photo_' + $this.attr("name") + '_id' )[0].files[0] ), 
    data.append( 'firstname', $( '#firstname_' + $this.attr("name") + '_id' ).val()),
    data.append( 'lastname', $( '#lastname_' + $this.attr("name") + '_id' ).val()),
    data.append( 'fathername', $( '#fathername_' + $this.attr("name") + '_id' ).val()),
    data.append( 'nationalID', $( '#nationalID_' + $this.attr("name") + '_id' ).val()),
    data.append( 'month', $( '#month_' + $this.attr("name") + '_id' ).val()),
    data.append( 'year', $( '#year_' + $this.attr("name") + '_id' ).val()),
    data.append( 'day', $( '#day_' + $this.attr("name") + '_id' ).val()),
    data.append( 'class', $( '#class_' + $this.attr("name") + '_id' ).val()),
    data.append( 'identity', $this.attr("name").val());
$.ajax({
        type         : 'POST',
        url          : 'http://localhost/wordpress/wp-content/themes/mytheme/process/edit-student-process.php',
        processData  : false,
        contentType  : false,
        data         : data,
        enctype      : 'multipart/form-data',
        dataType     : 'json',
    })
但有了这段代码,ajax重定向到php文件,该文件应该处理表单,而不是停留在表单上。问题在哪里

以及我表格的一部分:

<form class="form-horizontal edit_student" name="<?php echo $student['user_ID']; ?>" action="http://localhost/wordpress/wp-content/themes/danesh-sanat/process/edit-student-process.php" enctype="multipart/form-data" method="POST">
<input type="text" name="firstname_<?php echo $student['user_ID']; ?>_id" id="firstname_<?php echo $student['user_ID']; ?>_id" class="form-control" value="<?php echo $student['user_firstname']; ?>">
<input type="text" name="lastname_<?php echo $student['user_ID']; ?>_id" id="lastname_<?php echo $student['user_ID']; ?>_id" class="form-control" value="<?php echo $student['user_lastname']; ?>">

如果有重定向,则它不是来自FormData。向我们展示AJAX调用使用async:FalsNot working的函数。我有另一个类似于此的ajax,但不同之处在于,它在data.append()中没有$this.attr(“name”),这样就可以了。这就是问题所在吗?这是什么?您是否正在阻止提交
表单
?你的问题遗漏了一些context@domasync false已被弃用,不应以任何方式使用。如果您有重定向,它不是来自FormData。向我们展示AJAX调用使用async:FalsNot working的函数。我有另一个类似于此的ajax,但不同之处在于,它在data.append()中没有$this.attr(“name”),这样就可以了。这就是问题所在吗?这是什么?您是否正在阻止提交
表单
?你的问题遗漏了一些context@domasync false已弃用,无论如何都不应使用