如何运行运行帖子网址?

时间:2011-05-10 15:41:38

标签: asp-classic

我要做的是基本上运行脚本并将数据发布到页面,但页面不在服务器上。所以我不想运行重定向,只需在用户点击按钮时在后面运行一个网页?

我试过......

    set httpRequest = CreateObject("WinHttp.WinHttprequest.5.1")
Dim var1

var1 = Request("username")

on error resume next
httpRequest.Open "POST", "http://www.example.com", True
httpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.send var1
set httpRequest = nothing

但这似乎不起作用。所以我想建立网址http://www.example.com?username并运行它?

2 个答案:

答案 0 :(得分:0)

最简单的方法是包含对jQuery脚本库的引用并使用 .ajax的

http://api.jquery.com/jQuery.ajax/

电话只是:

<html>
 <head>
 <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" ></script>
 </head>
<body>
bip
<div id="result"> results to get replaced here</div>
<div id="msg" style="color:Red">any errors will show here</div>
<input type="button" value="click me" id="loadButton" />

<script language="javascript" type="text/javascript">

        //ensure jQuery is loaded before calling script
    $(document).ready(function () {
        alert('ready');
        $('#loadButton').click(function () {
            alert('Handler for .click() called.');
            $.ajax({
                url: 'yoursite/yourpage',
                error: function (xhr, ajaxOptions, thrownError) {
                    alert('doh an error occured. look at the error div above : )');
                    $('#msg').html(xhr.status + ' ' + thrownError); ;
                },
                data: "{'someparam':'someparamvalue','someparam2':'someparamvalue2'}",
                success: function (data) {
                    $('#result').html(data);
                    alert('Load was performed.');

                }
            });
        });
    });

</script>

</body>
</html>

答案 1 :(得分:0)

你的问题很可能是这一行:

httpRequest.Open "POST", "http://www.example.com", True

你的“真实”是说在异步模式下运行,即在继续之前不要等待响应。然后,您正在立即销毁该对象,因此请求永远不会变得很远。将“True”更改为“False”,您应该看到结果命中另一台服务器。


编辑1:

还注意到你没有正确格式化POST数据,它应该采用传统的url格式化foo=bar,因此需要像这样修改发送行:

httpRequest.send "name=" & var1

对不起,我第一次没有发现这个!


编辑2:

以下是使用WinHttpRequest进行工作GET事务的示例:

Function GetHTTP(strURL)

    Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
    objWinHttp.Open "GET", strURL, False
    objWinHttp.Send

    GetHTTP = objWinHttp.ResponseText

    Set objWinHttp = Nothing

End Function

如果你真的需要一个GET事务,你可以使用以下功能:

strResponse = GetHTTP("http://www.example.com/?name=" & Request("username"))

由于您不需要回复,只需忽略其中的strResponse

参考:

NeilStuff.com - Open Method

相关问题