/    Sign up×
Community /Pin to ProfileBookmark

send message and username

hello. i need a solution for my web project. it seams simple but i can’t get it working.
this is the deal:

user is register and loged in. he is viewing someones profile. so i have a php on witch i have a username (in form of php variable) of user browsing the site (user1) AND username of user who’s profile is viewed (user2).
i need to have an option so that user browsing the site(users 1) can send a message to user2 without refreshing or redirecting page.

i can successfully send message text to php that will write it into database via js file, i also can send a user2 username to php that will write it into database via js file but only separately.
i need to send bouth message text (form) AND user2 username to php file that will write this to database. All WITHOUT refreshing page or redirecting (ajax).

Please help!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@nibusterauthorNov 05.2009 — ok here some javascript code. this code updates original php files with text filled in the text box (write message) and sends it to the destination php (sendit.php) that writes data into database.

[B]function doHttpRequest2() { // This function does the AJAX request

http.open("GET", "sendit.php?txt1="+document.getElementById('txt1').value, true);

http.onreadystatechange = getHttpRes;

http.send(null);

}[/B]



is there a way to pass a php variable $username2 to destination file (sendit.php) thrue this function?
Copy linkTweet thisAlerts:
@nibusterauthorNov 05.2009 — ok here some javascript code. this code updates original php files with text filled in the text box (write message) and sends it to the destination php (sendit.php) that writes data into database.

[B]function doHttpRequest2() { // This function does the AJAX request

http.open("GET", "sendit.php?txt1="+document.getElementById('txt1').value, true);

http.onreadystatechange = getHttpRes;

http.send(null);

}[/B]



is there a way to pass a php variable $username2 to destination file (sendit.php) thrue this function?[/QUOTE]


[B]txt1[/B] is id of text area that is in the html file (form file).
Copy linkTweet thisAlerts:
@nibusterauthorNov 05.2009 — resolved! i'm not familiar with javascript so that's the reall problem. answer is

[B]function doHttpRequest2() { // This function does the AJAX request

http.open("GET", "sendit.php?txt1="+document.getElementById('txt1').value+"&username= <?php echo ($username); ?>", true);

http.onreadystatechange = getHttpRes;

http.send(null);

}[/B]
×

Success!

Help @nibuster 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.28,
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,
)...