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="CosmoPeak" data-source="post: 412365" data-attributes="member: 68352"><p>You're combining JavaScript events and jQuery, you need to use one or the other.</p><p></p><p>$("#admin").click(function() {}); is called when a div with ID 'admin' is clicked. There's no need to define a function within your handler (as in Mark's snippet). Just remove the onclick="" from your html.</p><p></p><p>A way to pass the ID to JavaScript would be to add a data attribute to your html. For example:</p><p></p><p>[code]<a id="#admin" data-id="<?php $array['id']; ?>">Username</a>[/code]</p><p></p><p>And updating Mark's code to get the id from the element:</p><p></p><p>[code]</p><p><script></p><p> $("#admin").click(function() {</p><p> var id = $(this).data('id');</p><p></p><p> $.ajax({</p><p> url: "getProfile.php",</p><p> method: "GET",</p><p> data: 'id=' + id,</p><p> success: function(data) {</p><p> $("#profile").html(data);</p><p> },</p><p> error: function() {</p><p> console.log('Error occurred');</p><p> }</p><p> });</p><p> });</p><p></script></p><p>[/code]</p><p></p><p>Again, you would also need to add the code which opens the modal on success as well.</p></blockquote><p></p>
[QUOTE="CosmoPeak, post: 412365, member: 68352"] You're combining JavaScript events and jQuery, you need to use one or the other. $("#admin").click(function() {}); is called when a div with ID 'admin' is clicked. There's no need to define a function within your handler (as in Mark's snippet). Just remove the onclick="" from your html. A way to pass the ID to JavaScript would be to add a data attribute to your html. For example: [code]<a id="#admin" data-id="<?php $array['id']; ?>">Username</a>[/code] And updating Mark's code to get the id from the element: [code] <script> $("#admin").click(function() { var id = $(this).data('id'); $.ajax({ url: "getProfile.php", method: "GET", data: 'id=' + id, success: function(data) { $("#profile").html(data); }, error: function() { console.log('Error occurred'); } }); }); </script> [/code] Again, you would also need to add the code which opens the modal on success as well. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
Javascript And PHP Ajax
Top