Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6936361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:13:27+00:00 2026-05-27T12:13:27+00:00

This is my ajax post <script language=JavaScript type=text/javascript> var num = 1; function ajax_post(){

  • 0

This is my ajax post

<script language="JavaScript" type="text/javascript">
  var num = 1;
  function ajax_post(){
  // Create our XMLHttpRequest object
  var hr = new XMLHttpRequest();
  // Create some variables we need to send to our PHP file
  var url = "javas.php";
  hr.open("POST", url, true);
   // Set content type header information for sending url encoded variables in the request
  hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  // Access the onreadystatechange event for the XMLHttpRequest object
  hr.onreadystatechange = function() {
  if(hr.readyState == 4 && hr.status == 200) {
        var return_data = hr.responseText;
        document.getElementById("status").innerHTML = return_data;
    }
}
// Send the data to PHP now... and wait for response to update the status div
hr.send("num=" + (++num)); // Actually execute the request
document.getElementById("status").innerHTML = "processing...";

}
</script>

Now I need to determine whitch class the button was clicked in (in php)

<?php
   //Getting posts from DB
   $event1 = mysql_query("SELECT post,date,memid FROM postaction WHERE memid = '$id' ORDER  BY date DESC LIMIT 5;");
  while ($row1 = mysql_fetch_array($event1))
  {
       $event = $row1['post'];
       $timeposted = $row1['date'];
       $eventmemdata = mysql_query("SELECT id,firstname FROM users WHERE id = '$id' LIMIT 1");
        while($rowaa = mysql_fetch_array($eventmemdata))
        {
            $name = $rowaa['firstname'];
            $eventlist = "$event <br> $name";
    }
        echo " <div id = 'eventer'> $timeposted <br>$eventlist</div> <input name='myBtn'            type='submit' value='increment' onClick='javascript:ajax_post();'>
               <input name='lol' type='submit' value='dec' onClick='javascript:ajax_posta();'>
               <div id = 'status'>lol</div>";
        echo "<br>";
  }
?>
</span>
</div>

When the button is clicked, the ajax function is called, however the function is being displayed in the first status div rather than in the div/class the button was clicked in.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:13:28+00:00Added an answer on May 27, 2026 at 12:13 pm

    At first, you need to realize that “id” attribute of the tag is supposed to be unique. So the correct approach to implement this would be to differentiate the IDs for exemple appending a unique number to them. Kinda like this:

    $i = 0;
    while ($row1 = mysql_fetch_array($event1))
    {
       $i++;
    
       ...
    
       echo " ... <input type='submit' name='lol' value='dec$i' />
           <div id='status$i'>...</div>";
    }
    

    You can then check for the number you get after the command (I know this is crude)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<html> <head> <title>Untitled 1</title> <script language=javascript type=text/javascript src=../js/jquery.js></script> <script type=text/javascript language=javascript> $(document).ready(function() { $(#usermsg).keypress(function(e)
I'm doing a jQuery AJAX post like this: var form = $(#formid); form.submit(function() {
Hai this is my jquery function, function getRecordspage(curPage, pagSize) { $.ajax({ type: POST, url:
So in default.aspx I have the code <script type=text/javascript> function validateForm() { test(); //here
How to pass multiple checkboxes using jQuery ajax post this is the ajax function
I always see the code like this in the blogs: $.ajax({ type: POST, contentType:
I have a javascript function that works as I would like : <script language=javascript
This relates to my previous post: jQuery .load Method causing page refresh AJAX I
How can I modify this: /services/type/single_dwelling/ to this: /ajax/services/single_dwelling/development Currently I have: linkUrl =
Could someone tell me if this: $.ajax({ url: 'test.html', success: function(data) { alert(Data Loaded:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.