jqueryajaxpost可以';不要发送数据
我有HTML表单,数据通过jQuery发送到本地PHPscript和远程php。问题是我无法将数据发送到远程PHP,为此我尝试使用jQueryAjax html代码:jqueryajaxpost可以';不要发送数据,jquery,Jquery,我有HTML表单,数据通过jQuery发送到本地PHPscript和远程php。问题是我无法将数据发送到远程PHP,为此我尝试使用jQueryAjax html代码: <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <script type="text/javascript" s
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<script type="text/javascript" src='jquery.js'></script>
<script type="text/javascript" src='e.js'></script>
<h2>PHP Form Validation Example</h2>
<p><span class="error">* required field</span></p>
<form method="post" id="registration" action="function.php">
Name: <input type="text" id="nameq" name="name" value="">
<span class="error">* </span>
<br><br>
E-mail: <input type="text" id="email" name="email" value="">
<span class="error">* </span>
<br><br>
Website: <input type="text" id="website" name="website" value="">
<br><br>
Comment: <textarea id="comment" name="comment" rows="5" cols="40"></textarea>
<br><br>
Gender:
<input type="radio" id="gender" name="gender" value="female">Female
<input type="radio" id="gender" name="gender" value="male">Male
<input type="radio" id="gender" name="gender" value="other">Other
<span class="error">* </span>
<br><br>
<button id="button" type="submit" form="registration">Submit</button>
</form>
</html>
$(“#按钮”)。单击(函数()
Mozilla Firefox 68显示“NS_绑定_中止”,Chrome 76无法发送$(“#按钮”).submit(函数()
Mozilla Firefox没有显示任何内容,无法发送,Chrome无法发送$。ajaxSetup({async:false})
两个浏览器都能正常工作,但我不想使用它我做错了什么,只更改e.js有解决方案吗?谢谢欢迎使用Stackoverflow 您的情况是,
在调用单击事件之前正在提交表单。您需要在提交表单时使用触发该get的事件
$( document ).ready(function() {
$("#registration").submit(function( event ) {
event.preventDefault();
var url = $(this).attr('action');
var cln = $("#nameq").val();
$.post(url, {"cln": cln});
});
});
这里的关键是方法调用event.preventDefault()
从文件中引用
jQuery的提交事件在实际提交之前触发,因此我们可以
通过调用事件对象取消提交事件
很抱歉,我的问题不清楚,但我认为这是一个误解。我的目标是希望在本地php脚本function.php和远程php中接收数据。现在:
$(document).ready(function() {
$("#registration").submit(function(event) {
event.preventDefault();
var cln = $("#nameq").val();
$.post("https://test/index.php", {"cln": cln});
});
});
我可以在我的远程php脚本中接收数据,但是数据不会被发送到本地php-function.php.With$.ajaxSetup({async:false}):
有延迟(我的站点正在等待远程php脚本的答复)我不喜欢它。我想同时将数据发送到本地和远程php脚本不是吗,在这种情况下,使用from完全过时了吗?如果他删除表单,他将不会收到提交,单击也会起作用?是的,这也是有意义的。我只能在远程php脚本中接收数据,但不能在本地脚本中接收数据php@alex对不起,是我我不明白你所说的本地PHP和远程PHP是什么意思。你能详细说明一下吗?本地PHP是通过传统的提交(和)方式通过表单发送数据的地方。远程PHP是我希望通过jQuery ajax post发送数据的地方。因此,当用户在我的表单上键入数据并单击提交时,数据应该“同时”发送到我的本地和远程PHP文件
$(document).ready(function() {
$("#registration").submit(function(event) {
event.preventDefault();
var cln = $("#nameq").val();
$.post("https://test/index.php", {"cln": cln});
});
});
$(document).ready(function() {
$("#button").click(function() {
var cln = $("#nameq").val();
$.ajaxSetup({async: false});
$.post("https://test/index.php", {"cln": cln});
});
});