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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:49:04+00:00 2026-05-27T22:49:04+00:00

I want to extract some data from the database without refreshing a page. What

  • 0

I want to extract some data from the database without refreshing a page. What is the best possible way to do this?

I am using the following XMLHTTPRequest function to get some data (shopping cart items) from cart.php file. This file performs various functions based on the option value.
For example: option=1 means get all the shopping cart items. option=2 means delete all shopping cart items and return string "Your shopping cart is empty.". option=3, 4…and so on.

My XHR function:

    function getAllCartItems()
    {
        if(window.XMLHttpRequest)
        {
            allCartItems = new XMLHttpRequest();
        }
        else
        {
            allCartItems=new ActiveXObject("Microsoft.XMLHTTP");
        }

        allCartItems.onreadystatechange=function()
        {
            if (allCartItems.readyState==4 && allCartItems.status==200)
            {
                document.getElementById("cartmain").innerHTML=allCartItems.responseText;
            }
            else if(allCartItems.readyState < 4)
            {
                 //do nothing
            }
        }
        var linktoexecute = "cart.php?option=1";
        allCartItems.open("GET",linktoexecute,true);
        allCartItems.send();
    }

cart.php file looks like:

    $link = mysql_connect('localhost', 'user', '123456'); 
    if (!$link)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('projectdatabase');
    if($option == 1) //get all cart items
    {
        $sql = "select itemid from cart where cartid=".$_COOKIE['cart'].";";
        $result = mysql_query($sql);
        $num = mysql_num_rows($result);
            while($row = mysql_fetch_array($result))
            {
                 echo $row['itemid'];
            }
    }
    else if($option == 2)
    {
            //do something
    }
    else if($option == 3)
    {
            //do something
    }
    else if($option == 4)
    {
            //do something
    }

My Questions:

  1. Is there any other way I can get the data from database without
    refreshing the page?
  2. Are there any potential threats (hacking, server utilization,
    performance etc) in my way of doing this thing? I believe a hacker
    can flood my server be sending unnecessary requests using option=1,
    2, 3 etc.
  • 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-27T22:49:05+00:00Added an answer on May 27, 2026 at 10:49 pm

    I don’t think a Denial of Service attack would be your main concern, here. That concern would be just as valid is cart.php were to return HTML. No, exposing a public API for use via AJAX is pretty common practice.

    One thing to keep in mind, though, is the ambiguity of both listing and deleting items via the same URL. It would be a good idea to (at the very least) separate those actions (or “methods”) into distinct URLs (for example: /cart/list and /cart/clear).

    If you’re willing to go a step further, you should consider implementing a “RESTful” API. This would mean, among other things, that methods can only be called using the correct HTTP verb. You’ve possibly only heard of GET and POST, but there’s also PUT and DELETE, amongst others. The reason behind this is to make the methods idempotent, meaning that they do the same thing again and again, no matter how many times you call them. For example, a GET call to /cart will always list the contents and a DELETE call to /cart will always delete all items in the cart.

    Although it is probably not practical to write a full REST API for your shopping cart, I’m sure some of the principles may help you build a more robust system.

    Some reading material: A Brief Introduction to REST.

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

Sidebar

Related Questions

I want to use ADO.net to extract some data from an Excel file. This
HI, I want to extract data from a website but it uses some strange
I'm getting some data from my database and using linq to calculate sums and
I want to extract some hourly data from rrdtool databases in order to create
i have some problem to extract some data from html source. following is sniffit
I'm new to python. I want to extract some text from the CNN website.
I want to extract information from a web page. The page has m nodes,
I've got a xml that I'm parsing and trying to extract some data from.
I want to scrape string data from some binary text files that contain embedded
I am trying to extract some data from an XML input with 6 lines,

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.