/    Sign up×
Community /Pin to ProfileBookmark

help with ajax

Hello I am new in ajax stuff and have a question

I have button with is sending data to my php script to save it… when ever I am clicking send button I am going there, I did put in the end return false it still doesn’t work.. Please can some one help here is my code…

var xmlHttp = false;
try {
xmlHttp = new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch(e) {
try {
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch(e) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != ‘undefined’) {
xmlHttp = new XMLHttpRequest();
}

function sendData() {
if (xmlHttp) {
text = document.getElementById(“info”);
xmlHttp.open(‘POST’, ‘add.php’);
xmlHttp.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);
xmlHttp.send(‘message=’ + text.value);
text.value = “”;
text.focus();
}
}
….

<form action=”add.php”>
<input type=”text” name=”info” /><br/>
<input type=”submit” onclick=”javascript:sendData();return false;” value=”Send”/>
</form>

Please help ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@jeanlucaJan 17.2010 — it works for me (without the javascript). BTW you can drop the [B]javascript:[/B]!

Furthermore, I think you have a javascript error. When an error occures the browser stops executing the javascript and submits the form
×

Success!

Help @pulsu 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...