【发布时间】:2017-05-18 05:00:03
【问题描述】:
我是第一次这样做。我想要在 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>
请帮忙
【问题讨论】:
-
你的 jQuery 代码中可能有错字:
daatType而不是dataType我猜 -
status 变量的值是多少?您可以使用 url 参数将数据带到下一页。例如如果下一页是www.abc.com/def.html,那么你可以做www.abc.com/def.html#这是数据。在新的 html 页面中,您可以使用 javascript 获取此值: var x = location.hash;
-
请明确您的数据是短数据还是长数据?如果它很短且不敏感,您可以像这样传递 URL。 window.location.href = site_url + 'status/' + 数据;在你的成功函数中做到这一点。
标签: javascript jquery html ajax