我如何将这个变量添加到上面的代码中?我需要传递这两个变量。我试过了,但代码没有像我预期的那样工作(警报不适用于更改)。
name: $('#name').val(),
email: $('#email').val()
<script type="text/javascript">
jQuery(document).ready(function() {
$.ajax("valid.php", {
type: "POST",
dataType: "json",
name: $('#name').val(), //here??
email: $('#email').val() //here??
success: function(step) {
if (step.first) {
alert("fdsgdfg");
}
if (step.second) {
alert("dfgdfg");
}
}
});
});
</script>
谢谢!
最佳答案
将另一部分添加到您的 ajax 调用中,称为“数据”。
<script type="text/javascript">
jQuery(document).ready(function() {
$.ajax("valid.php", {
type: "POST",
dataType: "json",
data: { name: $('#name').val(), email: $('#email').val() },
success: function(step) {
if (step.first) {
alert("fdsgdfg");
}
if (step.second) {
alert("dfgdfg");
}
}
});
});
或者:
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
关于php - 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5628743/