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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:10:57+00:00 2026-06-03T23:10:57+00:00

I have a project where I need to write text from a database into

  • 0

I have a project where I need to write text from a database into an HTML5 canvas / Javascript application.

To select this content, I’ve specified an attribute “reference” where I can ask the database with the content id, for example: index.php?reference=exercise1.

I have used AJAX because I need to get the text content into a Javascript variable in order to write data on canvas.
My solution is working but I need to get the reference attribute value from Javascript document.URL and not PHP $_GET.

Here is the code:

var url = decodeURIComponent(document.URL);
var attr = "reference";
var attrPos = url.lastIndexOf(attr);
var referencePos = attrPos + attr.length + 1;
var reference = url.substr(referencePos,url.length);

What I’m doing seems not to be the clean way to me.

First, ?reference= should be used with PHP $_GET and not be hacked through Javascript.

Then, I have to use lastIndexOf() instead of the search() method in order to get the good value if my application is located in a folder named “reference”.

Still, if I have my project in a folder named “reference” with a URI like localhost/reference/projectfolder/index.php and a reference named “projectfolder” in the database, it will load the content even if I have not asked for index.php?reference=projectfolder

From your experience, what is the best solution in my case: be able to get PHP/MySQL data to use with Javascript. Ajax seems to be the best way but as you can see it’s not clean, at least my solution.

Thanks for your help.

  • 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-03T23:10:59+00:00Added an answer on June 3, 2026 at 11:10 pm

    Still, if I have my project in a folder named “reference” with a URI
    like localhost/reference/projectfolder/index.php and a reference named
    “projectfolder” in the database, it will load the content even if I
    have not asked for index.php?reference=projectfolder

    if you want the document to be empty when you are requesting just index.php, check if $_GET[“reference”] is set and then return an empty body.

    From your experience, what is the best solution in my case: be able to
    get PHP/MySQL data to use with Javascript. Ajax seems to be the best
    way but as you can see it’s not clean, at least my solution.

    Check this gist on how to return JSON in your body https://gist.github.com/2627924

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

Sidebar

Related Questions

I have a project where I need to update a labels text from inside
The Junits I have in my project need to load property files from the
I have a project where I need to take input text and render it
I am attempting to write an application in which I have two text fields
I have a project where I need to compare multi-chapter documents to a second
i need to have one project on asp.net mvc 1 but i want to
I have a large project but I need only some folders in my svn
I have a project in which I would need to copy files found within
I have a project in Java and I need to make a code listing
I have a project in which I need to display multiple UITableView instances inside

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.