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

  • Home
  • SEARCH
  • 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 124641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:01:57+00:00 2026-05-11T05:01:57+00:00

I am trying to send a php script some content to be stored in

  • 0

I am trying to send a php script some content to be stored in a database via ajax. I am using the jQuery framework. I would like to use a link on a page to send the information. I am having trouble writing the function that will send and receive the information, everything that I have tried is asymptotic.

EDIT

The idea is that the user will click the link, and a column called ‘show_online’ (a tiny int) in a table called ‘listings’ will update to either 1 or 0 (**a basic binary toggle!) On success, specific link that was clicked will be updated (if it sent a 1 before, it will be set as 0).

EDIT

There will be 20-30 of these links on a page. I have set each containing div with a unique id (‘onlineStatus’). I would rather not have a separate js function for every instance.

Any assistance is much appreciated. The essential code is below.

<script type='text/javascript'>      function doAjaxPostOnline( shouldPost, bizID ){         load('ajaxPostOnline.php?b='+bizID+'&p='+shouldPost', jsonData, callbackFunction); function callbackFunction(responseText, textStatus, XMLHttpRequest) {   // if you need more functionality than just replacing the contents, do it here }          }     } </script>      <!-- the link that submits the info -->:  <div id='onlineStatus<?php echo $b_id ?>'> <a href='#' onclick='doAjaxPostOnline( 0, <?php echo $b_id ?> ); return false;' >Post Online</a> </div>   

ajaxPostOnline.php

<!-- ajaxPostOnline.php ... the page that the form posts to --> <?php     $id = mysql_real_escape_string($_GET['b']);     $show = mysql_real_escape_string($_GET['p']);      if( $id && ctype_digit($id) && ($show == 1 || $show == 0) ) {         mysql_query( 'UPDATE listing SET show_online = $show         WHERE id = $id LIMIT 1' );     }      if($result) {         if($show == '0'){             $return = '<a class='onlineStatus' href='#' onchange='doAjaxPostOnline( 1, <?php echo $b_id ?> ); return false;' >Post Online</a>';         }         if($show == '1'){             $return = '<a class='onlineStatus' href='#' onchange='doAjaxPostOnline( 0,  $b_id ); return false;' >Post Online</a>';         }         print json_encode(array('id' => $id, 'return' => $return));     } ?> 
  • 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. 2026-05-11T05:01:58+00:00Added an answer on May 11, 2026 at 5:01 am

    The load() function in jQuery is really cool for this sort of thing.

    Here’s an example. Basically, you have an outer div as a container. You call a script/service which returns html. You have a div in that html with an id that you will refer to later in the ajax call. The replacement div replaces the inner html of the container div. You pass your data as a json object as the second parameter to the load method, and you can pass a reference to a callback function as the third parameter. The callback function will receive every possible piece of information from the response (the full response text for further parsing/processing, the http status code, and the XMLHttpRequest object associated with this ajax call).

    $('#id_of_some_outer_div').load('somepage.php #id_of_replacement_div', jsonData, callbackFunction);  function callbackFunction(responseText, textStatus, XMLHttpRequest) {   // if you need more functionality than just replacing the contents, do it here } 

    so, in your case you’re talking about replacing links. Put the original link inside of a div on both sides of the operation.

    Here’s the link to the jQuery api doc for load():

    load

    EDIT:

    In response to your comment about doing multiple replacements in one pass:

    You can have the callback function do all the work for you.

    1. Add a unique css class to all divs that need replacing. This will allow you to select all of them in one shot. Remember that html elements can have more than one css class (that’s what the ‘c’ in CSS means). So, they’d all be <div id='[some unique id]' class='replace_me'... Then, if you have a variable set to $('div.replace_me'), this will be a collection of all divs with the replace_me style.
    2. Whatever elements that come from the ajax call (whether they’re another div container or just a single ‘a’ element) should have a unique id similar to the container they’re to be inserted into. For example, div_replace1 would be the id of a container and div_replace1_insert would be the id of the element to be inserted
    3. Inside the callback function, iterate over the replacements using $('div.replace_me').each(function(){ ...
    4. Inside each iteration the ‘this’ keyword refers to the current item. You can grab the id of this item, have a variable like var replacement_id = this.id + '_insert'; (as in the example above) which is now the unique id of the element you’d like to insert. $('#' + replacement_id) will now give you a reference to the element you want to insert. You can do the insertion something like this: this.html( $('#' + replacement_id) );

    You may have to edit the code above (it’s not tested), but this would be the general idea. You can use naming conventions to relate elements in the ajax return data to elements on the page, iterate the elements on the page with ‘each’, and replace them with this.html()

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

Sidebar

Ask A Question

Stats

  • Questions 107k
  • Answers 107k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Events are raised synchronously by default. Since MulticastDelegates are designed… May 11, 2026 at 9:04 pm
  • Editorial Team
    Editorial Team added an answer SOAP is encapsulated with the Web Service model in ASP.Net.… May 11, 2026 at 9:04 pm
  • Editorial Team
    Editorial Team added an answer The reason why your example doesn't work is that you're… May 11, 2026 at 9:04 pm

Related Questions

I am trying to use an ajax 'POST' call through the jquery $.ajax function
I've been doing PHP/MySQL websites with shared hosting providers for the last couple years.
I am trying to get the index of an element using jQuery to send
I am trying to send something to serial port (r232) with PHP. I am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.