我是第一次这样做。我想要在 HTML 页面中使用 AJAX 调用和 jQuery 的另一个 HTML 页面的数据。 下面是我的代码
这是我的 .js 代码
<script type="text/javascript">
$(document).ready(function()
{
$('#submit').click(function(){
var name =$('#name').val();
var pass =$('#passsword').val();
if(name=='' || pass==''){
alert('first fill the details');
}
else {
$.ajax({
method:'POST',
url:"login.html",
data:{name:name,
password:pass},
daatType:"HTML",
success:function(status) {
alert('success');
$('#div').html(status);
}
})
}
})
})
这是我的HTML代码
<form>
<label>Name:</label><input type="text" id="name"><br>
<label>Password:</label><input type="text" id="password"><br>
<button type="submit" id="submit" >Submit</button>
</form>
<h2 id="div"></h2>
请帮忙
最佳答案
将 dataType:"HTML"
更改为 dataType:"json"
dataType:'json' // its mean server return type data
鉴于
contentType:'json' // send data type to server should be json
关于javascript - 在 HTML 中使用 Jquery 进行 Ajax 调用并响应其他 Html 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44021570/