Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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 使用ajax和变量id提交刷新表单1输入_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 使用ajax和变量id提交刷新表单1输入

Javascript 使用ajax和变量id提交刷新表单1输入,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,仅提交id为“formid-”且$I始终更改的表单后,我需要在span中刷新数字而不重新加载页面。我也需要ajax代码以及如何将其组合在一起。我发现了类似的东西,但无法使其工作: jQuery.on('submit', function(e){ e.preventDefault(); var formID = $(this).data('i'); //call $.ajax(); } 和ajax: $.ajax({ type: 'POST', url: $("form").at

仅提交id为“
formid-
”且
$I
始终更改的表单后,我需要在span
中刷新数字而不重新加载页面。我也需要ajax代码以及如何将其组合在一起。我发现了类似的东西,但无法使其工作:

jQuery.on('submit', function(e){
e.preventDefault();
var formID = $(this).data('i');

//call $.ajax();

} 

和ajax:

$.ajax({
  type: 'POST',
  url: $("form").attr("action"),
  data: $("form").serialize(), 
  or your custom data either as object {foo: "bar", ...} or foo=bar&...
  success: function(response) { ... },
 });
我的表格是这样的:


<form action="" method="post" id="formid-<?php echo $i; ?>"> 
        <h6  class="badge badge-warning font top-8"><input type="submit" name="send" value="Subscribe">
   <span class="badge badge-light">

 <?php 

 echo $subscriptions; // this is the number

   ?>

   </span>
  <span class="sr-only">Subscribe</span>

</h6>
</form> 

jQuery.on('submit')
处理程序无效。即使您正在使用,也应该使用第二个参数作为选择器

jQuery(“form[id^='form-']”)。关于('submit',函数(e){
e、 预防默认值();
var formID=$(this.data('i');
//调用$.ajax();
}
}

注意:对于事件委托,它将是
jQuery(“body”)。关于(“提交”,“表单[id^='form-']”,function(){})

据我所知,这不是一个完整的代码,对我来说不起作用,我对javascript知之甚少,抱歉)我通过php更新提交表单