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 8407785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:27:45+00:00 2026-06-09T23:27:45+00:00

I have a function which updates a database via ajax. My issue is then

  • 0

I have a function which updates a database via ajax. My issue is then how to update the data displayed on the page to show updated details. The POST data can vary and therefore the datastring would be something like this:

        var dataString = '[name resource we are editing]=1' + 
        '&para1='+ para1 + 
        '&para2=' + para2+
        '&para3=' + para3

I want the function below to split or loop through each of the POST variables in the datastring to update the text of an element on the page. I cannot figure out how.

function editAccount(dataString, details, form){
        status = $(".status");
        $.ajax({  
          type: "POST",  
          url: "<?php echo BASE_PATH; ?>/edit/",  
          data: dataString,  
            success: function(response) { 
                $.each(response, function(key, value) { 
                success_code = key;
                message = value;
               });

              if(success_code == 1){
                status.text(message).addClass("valid");
                //show details and hide form
                $("#" + details).show();
                $("#" + form).hide();   
                            //HOW to do below?
                //update details being displayed with datasource data 
                //loop through dataString to assign eg. $('#para1')text(para1);

              } else {
                status.text(message).addClass("invalid");
              }
            },
            error: function(response){ 
            status.text("There was a problem updating your details into our database.  Please contact us to report this error.").addClass("invalid");
          }  
        });  

    }
  • 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-06-09T23:27:46+00:00Added an answer on June 9, 2026 at 11:27 pm

    As mentioned in a previous comment, I would suggest declaring the dataString variable as an object:

    var dataString = { '[name resource we are editing]' : 1, 
            'para1': para1, 
            'para2': para2,
            'para3': para3
            }
    

    Now it’ll be much easier to loop over the params, just using the function each, for instance, which you already use in your code:

    $.each(dataString, function(key, value) {
        // Do stuff with each param
    });
    

    EDIT:

    As @Qpirate suggests, you also can use the javascript for loop:

    for(var key in dataString){
        // value => dataString[key]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function to take ownership of a job which updates the database
I have a PL/SQL function (running on Oracle 10g) in which I update some
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;
I have javascript/jquery code which fetches info and updates it into the database with
I have created a function that updates some values from a database that I
We have data that's updated nightly in a database residing in the same instance
Let's say I have a counter function which updates a counter using raw SQL:
I have a form which I call via AJAX (for use on a CMS)
I have the following function which reads from a firebird database. The Function works
hi i have function which is called by tinker listbox so i cannot return

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.