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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:45:13+00:00 2026-06-10T16:45:13+00:00

I want to return an array from a php function to my ajax call.

  • 0

I want to return an array from a php function to my ajax call. After that I want to use the array values from the page the ajax call is made.

So this is my ajax call:

        $(function() {
        $("#find").click(function() {

            var url = $("#form_url").val();
            var dataString = 'url=' + url;

            $.ajax({
                type: "POST",
                url: "/ajax/add_url.php",
                data: dataString,
                }).done(function( result ) {
                    myresult(result);
            });

            return false;
        });
    });


 function myresult(result) {
var result_lines = result.split("<splitter>");    
if (result_lines[0] == '1') { 
    $('#content_error').html(result_lines[1]).fadeIn(250);
    $('#content_error').delay(1500).fadeOut(500);
} else if (result_lines[0] == '2') { 
    $('#content_success').html('Succesfully get images').fadeIn(250);
    $('#url_result').delay(500).fadeIn(500);
    $('#content_success').delay(1500).fadeOut(500);
    alert(eval(data));
}
return true;   

}

and this is my php script:

 if($_POST['url']) {

    $url = $Db->escape($_POST['url']);

        $html = file_get_html($url);
        $count = 0;
        $goodfiles = array();

        foreach($html->find('img') as $element) {

            $pic = url_to_absolute($url, $element->src);

            if(!empty($pic)){

                $pics = parse_url($pic);
                list($width, $height, $type, $attr) = getimagesize($pic);

                if($pics["scheme"]=="http" && $width >= 300 && $height >= 250) {

                    array_push($goodfiles,$pic);
                    $_SESSION['pictures'] = $goodfiles;
                    $count++;

                }
            }
      }


        if($count == 0){ 

            $_SESSION['count'] = 'empty'; 
            echo "1<splitter>"; 
            echo "No items found with the correct size"; 


        }else{

            $_SESSION['count'] = $count;
            echo "2<splitter>";
            echo json_encode($_SESSION['pictures']); 

        }

            $_SESSION['url'] = $url;
            $html->clear();
            $empty = 1;
    }

  }

when the ajax call is successful I use json_encode on the array to use it on my php page. But I don’t know how I get this array to a javascript on the page the ajax call was made of.

right now I’m receiving the following content:

[“image.jpeg”,”image.jpg”]

And I want to put this in a javascript array…

  • 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-10T16:45:15+00:00Added an answer on June 10, 2026 at 4:45 pm

    The error is this with this line:

    var result_lines = result.split("<splitter>");
    

    result (the AJAX response) is an object or array (depending on the nature of your JSON) but you are trying to call a string method (split()) on it.

    This would cause an error in your JS console – always check the console.

    Finally, eval() is evil and almost never required except in exceptional circumstances. Try to avoid it.

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

Sidebar

Related Questions

I want my ajax call to only return the values from my array in
I want to return a set of values from function till the point they
Hey guys I have an ajax jquery function that receives data from a php
This php code is called through ajax from javascript and should return a numeric
I'm using Array.sample to return a random element from an array. I want to
Good Day, I'm creating a VBScript function to return an array. But I want
I want to remove an element from a PHP array (and shrink the array
I want to call a PHP webservice from my J2ME program. Here is the
I have a PHP function that returns something: function myfunction() { $array = array('one',
I have a simple PHP function that will grab information from a database based

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.