Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
Javascript And PHP Ajax
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Berk" data-source="post: 412347" data-attributes="member: 63611"><p>hello</p><p></p><p>so what i'm trying here is, when i click <a href="" id="admin">e<?php echo $array['username']; ?></a> I want it to pop a modal (custom css, not bootstrap) with including some information about the $array['username'];</p><p>I tried AJAX but it didn't send any response. Either success or error.</p><p>My code:</p><p>[SPOILER="Code"]</p><p>[SPOILER="Javascript"]</p><p>[CODE]</p><p><script></p><p>$("#admin").click(function() {</p><p> function toggleProfile(id) {</p><p> $.ajax ({</p><p> url: "getProfile.php",</p><p> method: "POST",</p><p> data:id,</p><p> success: function(data) {</p><p> $("#profile").html(data);</p><p> },</p><p> error: function (jqXHR, exception) {</p><p> var msg = '';</p><p> if (jqXHR.status === 0) {</p><p> msg = 'Not connect.\n Verify Network.';</p><p> } else if (jqXHR.status == 404) {</p><p> msg = 'Requested page not found. [404]';</p><p> } else if (jqXHR.status == 500) {</p><p> msg = 'Internal Server Error [500].';</p><p> } else if (exception === 'parsererror') {</p><p> msg = 'Requested JSON parse failed.';</p><p> } else if (exception === 'timeout') {</p><p> msg = 'Time out error.';</p><p> } else if (exception === 'abort') {</p><p> msg = 'Ajax request aborted.';</p><p> } else {</p><p> msg = 'Uncaught Error.\n' + jqXHR.responseText;</p><p> }</p><p> console.log(msg);</p><p> }</p><p> });</p><p> } </p><p> });</p><p> </script></p><p>[/CODE]</p><p>[/SPOILER]</p><p>[SPOILER="PHP getProfile.php"]</p><p>[PHP]</p><p><?php</p><p>$id = $_POST['id'];</p><p>$q = $db->assoc($db->query("SELECT * FROM users WHERE id = '{$id}'"));</p><p>?></p><p> <div id="openModal" class="modalDialog"></p><p> <div></p><p> <a href="#close" title="Close" class="close">X</a></p><p> <div style="padding-top:20px;"></p><p> <h4>Profile</h4><hr><img src="http://domain.com/pictures/<?php echo $r['username']; ?>.png" style="border-radius: 5000px; float:right; width:300px; height:300px;"/></div></p><p> <h2><?php echo $q['username']; ?> </h2> <div style="padding:10px;"><?php if($q['is_away'] == 1) { ?><div style="border:5px solid rgb(115,56,128);border-radius:3px; height:25px;width:125px; background: rgb(0,0,0); font-weight:bold;color:white;padding:10px;"><center>This user is away</center></div></div><?php } ?></p><p> <p><B>Region</b>: <?php echo $q['region']; ?></p></p><p> <p><b>Rank</b>: <?php echo $q['rank']; ?></p></p><p><?php</p><p> if($user->hasGroup('4') || $user->hasGroup('5')){</p><p> ?></p><p> Admin actions<br></p><p> <form method="post" action="" ></p><p> <input type="submit" class="mws-button red" value="Log out this user." name="logout"></p><p> </form><br></p><p> <form method="post" action="" ></p><p> <input type="submit" class="mws-button red" value="Alert this user." name="alert"></p><p> </form><br></p><p> <form method="post" action="" ></p><p> <input type="submit" class="mws-button red" value="Suspend this user." name="suspend"></p><p> </form></p><p> <?php</p><p> </p><p> </p><p> if($_POST['logout']) {</p><p> $user->logoutUser($uid['id']);</p><p> }</p><p> </p><p> }</p><p> ?></p><p> </p><p></p><p></div></p><p></div></p><p></div></p><p></div></p><p>[/PHP]</p><p>[/SPOILER]</p><p>[/SPOILER]</p><p></p><p>It doesn't return anything. Maybe i'm missing something?</p><p></p><p>Any help appreciated.</p><p></p><p>Thanks</p></blockquote><p></p>
[QUOTE="Berk, post: 412347, member: 63611"] hello so what i'm trying here is, when i click <a href="" id="admin">e<?php echo $array['username']; ?></a> I want it to pop a modal (custom css, not bootstrap) with including some information about the $array['username']; I tried AJAX but it didn't send any response. Either success or error. My code: [SPOILER="Code"] [SPOILER="Javascript"] [CODE] <script> $("#admin").click(function() { function toggleProfile(id) { $.ajax ({ url: "getProfile.php", method: "POST", data:id, success: function(data) { $("#profile").html(data); }, error: function (jqXHR, exception) { var msg = ''; if (jqXHR.status === 0) { msg = 'Not connect.\n Verify Network.'; } else if (jqXHR.status == 404) { msg = 'Requested page not found. [404]'; } else if (jqXHR.status == 500) { msg = 'Internal Server Error [500].'; } else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.'; } else if (exception === 'timeout') { msg = 'Time out error.'; } else if (exception === 'abort') { msg = 'Ajax request aborted.'; } else { msg = 'Uncaught Error.\n' + jqXHR.responseText; } console.log(msg); } }); } }); </script> [/CODE] [/SPOILER] [SPOILER="PHP getProfile.php"] [PHP] <?php $id = $_POST['id']; $q = $db->assoc($db->query("SELECT * FROM users WHERE id = '{$id}'")); ?> <div id="openModal" class="modalDialog"> <div> <a href="#close" title="Close" class="close">X</a> <div style="padding-top:20px;"> <h4>Profile</h4><hr><img src="http://domain.com/pictures/<?php echo $r['username']; ?>.png" style="border-radius: 5000px; float:right; width:300px; height:300px;"/></div> <h2><?php echo $q['username']; ?> </h2> <div style="padding:10px;"><?php if($q['is_away'] == 1) { ?><div style="border:5px solid rgb(115,56,128);border-radius:3px; height:25px;width:125px; background: rgb(0,0,0); font-weight:bold;color:white;padding:10px;"><center>This user is away</center></div></div><?php } ?> <p><B>Region</b>: <?php echo $q['region']; ?></p> <p><b>Rank</b>: <?php echo $q['rank']; ?></p> <?php if($user->hasGroup('4') || $user->hasGroup('5')){ ?> Admin actions<br> <form method="post" action="" > <input type="submit" class="mws-button red" value="Log out this user." name="logout"> </form><br> <form method="post" action="" > <input type="submit" class="mws-button red" value="Alert this user." name="alert"> </form><br> <form method="post" action="" > <input type="submit" class="mws-button red" value="Suspend this user." name="suspend"> </form> <?php if($_POST['logout']) { $user->logoutUser($uid['id']); } } ?> </div> </div> </div> </div> [/PHP] [/SPOILER] [/SPOILER] It doesn't return anything. Maybe i'm missing something? Any help appreciated. Thanks [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
Javascript And PHP Ajax
Top