What i am trying to do is basically run a script and post data to a page but the page is not on the server. So i dont want to run a redirect, just run a webpage in the back when the user clicks on a button?
I have tried…
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
But this doesnt seem to work. So i want to built the url http://www.example.com?username and run it?
The easiest way is to include a reference to the jQuery script libraries and use
.ajax
http://api.jquery.com/jQuery.ajax/
a call is simply:
<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>