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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:59:28+00:00 2026-05-27T10:59:28+00:00

I have an ajax function search for keywords in a big database. The php

  • 0

I have an ajax function search for keywords in a big database. The php being called simply says “no” if there’s nothing, but if there are found records, it goes ahead and creates all of the HTML and returns the html, so that AJAX only needs to put the returned text into the html of a div. My problem is that I’d like to pass along a couple of variables, like the number of records found, etc.

So if I tried to put it in a statement that javascript could eval, I’m afraid that not only is all of the html potentially big enough to cause some sort of variable problems, but it also has a lot of single and double quotes, etc, that could unexpectedly end the variable before it’s supposed to. See the following

// (I know I don't have a single quote after data and that will break it. This is just an example
echo "{ status: 'success', total: '".count($relevance)."' data: ";
foreach ($relevance as $re) {        
    // tons of html is printed here
}
echo " }";

So the question is, how do I most effectively send back a whole gang of html code, along with some variables that can be easily eval’ed by JS?

  • 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-27T10:59:29+00:00Added an answer on May 27, 2026 at 10:59 am

    Use json_encode This will eliminate any errors you might have in trying to create your own json.

    $returnArray = array(
        'status'=>'success',
        'total' => count($relevance),
        'data' => ''
    );
    
    foreach ($relevance as $re) {        
        $returnArray['data'] .= $re; // + all long html code
    }
    
    echo json_encode($returnArray);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jQuery code. I have called an Ajax function file, file.php, that
I have ajax request result = $.ajax({ url: '/live-sell-search.php?id=123', success: function(result) { $('.results-list').html(result); }
I have a jquery-ajax function that sends data to a php script and the
The problem seems very strange. I have a AJAX helper function within a same
The problem is the following. We have lots of ajax call via $.ajax function.
I have some content from server using $.ajax() function. I try to replace some
I have written a simple jQuery.ajax function which loads a user control from the
I am using the jQuery $.ajax() function. I have put this into a parent
I have $.ajax({ url: identity, success: function(data) { ProcessIdentityServer(data) } }); When 'data' is
I have the following code that works on Firefox and Chrome $("#adicionarItem").click(function(){ $.ajax({ type:

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.