/    Sign up×
Community /Pin to ProfileBookmark

post data to server

Hi how to send data to server .i have written a code in javascript which will get data from server and then send it to server.How to make use of the xmlhttpreq.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@trandrusMar 17.2009 — what happens under the hood:

[CODE]
<html>
<head>
</head>
<body>

<script type="text/javascript">

function createRequest()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer 6+
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
// Internet Explorer 5
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}

return xmlHttp;
}


function add100(p) {

var reqObj = createRequest();

reqObj.onreadystatechange=function()
{
if(reqObj.readyState==4)
{
//callback

}
}

var url="add.php?p="+p+"&sid="+Math.random();
reqObj.open("GET",url,true);
reqObj.send(null);

}
</script>

<a href="#" onclick="add100(this.value);">Link 1</a>

</body>
</html>
[/CODE]


that will disallow caching by adding a random number to the request params. even better, use jquery ajax:

[CODE]
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
[/CODE]
×

Success!

Help @senthilarumugam spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...