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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:58:50+00:00 2026-05-13T05:58:50+00:00

i want to call a php with jquery ajax to perform some database things

  • 0

i want to call a php with jquery ajax to perform some database things and then return 2 lists of links. so i have to pass these two link lists back to jquery so it can display list 1 in the left side of the webpage and list 2 in the right side.

i created the lists in separate arrays that i send back to jquery with json_encode but i noticed that it escapes all the html characters.

<a>dog</a> became <a>dog<\/a>

so when i displayed the list in the html they werent links anymore.

how can i preserve the html codes in my returned arrays to jquery?

EDIT: is this the right way to go if you want to split up data from php so that jquery can display them in different locations in html?

// list 1
while($row = mysqli_fetch_assoc($saved_tags))
{
    $display_saved_tags[] = "<a id='showtag' href='answer.php?id=" . $row['id'] . "'>" . $row['name'] . "</a><br />";
}

// list 2
while($row = mysqli_fetch_assoc($related_tags))
{
    $display_related_tags[] = "<a id='showtag' href='answer.php?id=" . $row['id'] . "'>" . $row['name'] . "</a><br />";
}

// return lists to jquery
echo json_encode('display_saved_tags' => $display_saved_tags, 'display_related_tags' => $display_related_tags));
  • 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-13T05:58:50+00:00Added an answer on May 13, 2026 at 5:58 am

    json_encode‘s escape characters directly conflict with HTML output. I have had the same issue but decided to use an alternative solution at the time. I just had a thought that you could perhaps do this:

    $data = new stdClass();
    $data->html1 = base64_encode('<h1>html in here</h1>');
    $data->html2 = base64_encode('<p><strong>more html</strong></p>');
    echo json_encode($data);
    

    On the frontend:

    callbackFunction(json) {
        alert(base64_decode(json.html1));
        alert(base64_decode(json.html2));
    }
    

    You would need the javascript implementations of base64_decode and utf8_decode which can be found at:
    http://phpjs.org/functions/base64_decode:357

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

Sidebar

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.