这样请求数据,一下子就闪出来了,怎样来接收一下?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>fir</title>
</head>
<body>
<form id="form" method = "post" action = "http://www.kuaidi100.com/query?type=yuantong&postid=postttt&id=1&valicode=&temp=123">
    <label>用户名:</label>
    <input type="text"   value="100605028323"  postttt = "" id="txt" />
    <input type="submit" value="确定"  name="submit" id="sub"/>
</form>
<script>
    var txt = document.getElementById("txt");
    var btn = document.getElementById("sub");
    var form = document.getElementById("form");
    console.log(typeof form.action);
    btn.onclick= function () {
        var action = form.action;
        form.action = action.replace(/postttt/, txt.value);
    }
</script>
</body>
</html>


bestDove
浏览 1761回答 4
4回答

李夜

可以用 ajax 或者 jsonp 方法替换 form 元素的 post方法, 具体可以采用 jQuery 的 $.get() , $.post(), $.getJSON, $.ajax()等API ,并且将页面中的form标签换成普通的div即可.当然,你可以自己用原生 js 封装一个ajax方法,依据需求而定。

李夜

应该是后台没有开放端口。因为 ajax 遵守“同源策略”, 不在同一协议、域名、端口下的ajax请求一般获取不到数据,浏览器有报错,如下:可以选择线上调试,或者跟后台协商开放端口。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5