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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:45:29+00:00 2026-05-28T00:45:29+00:00

This code give me this error: c.apply is not a function All code works

  • 0

This code give me this error: c.apply is not a function
All code works well only if i use one function. However i am not sure about how use two functions. These lines are probably wrong :

 postHandler(<?php echo get_posts($db, 0, $_SESSION['posts_start']); ?>, <?php echo get_posts1($db, 0, $_SESSION['posts_start']); ?>);

and

var postHandler = function(postsJSON, postsJSON1) {
$.each(postsJSON, postsJSON1, function(i, post, post1) {

script

first function

function get_posts($db, $start, $number_of_posts) {
       //code
            return json_encode($posts);
        }

output:

string '[{"username":"Altitude software","foto_oferta":"thumb\/miniaturas\/oferta\/default_offer.jpg","actividades":"Some activities","id_oferta":77,"oferta":"Programador web" ...

second function

function get_posts1($db, $start, $number_of_posts) {
       //code
            return json_encode($posts1);
        }

output:

string '[{"id_offer":77,"tags":["c++","JAVA"]},{"id_offer":76,"tags":["ajax","php"]},{"id_offer":75,"tags":["PHP","JAVA"]}]'

js

var postHandler = function(postsJSON, postsJSON1) {
                $.each(postsJSON, postsJSON1, function(i, post, post1) {
                    var id = 'post-' + post.id_oferta;

                    $('<div></div>').addClass('post').attr('id',id)
                    .html('<div class="box_offers"><div class="rating_offer"></div><div class="post-title">' 
                            + post.oferta + '</div>  <div class="post-box"> <a class="oferta_val bold_username">'
                            + post1.tags + '</a></div><a id='+id+'hide class="post-more" >Descrição</a><div class="logo_offer">')
                            .appendTo($('#posts'));

                    $('#'+id+'hide').click(function() {
                        $('.'+id+'hidden').slideToggle('fast');
                    });
                }); 
            };

postHandler(<?php echo get_posts($db, 0, $_SESSION['posts_start']); ?>, <?php echo get_posts1($db, 0, $_SESSION['posts_start']); ?>);
  • 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-28T00:45:30+00:00Added an answer on May 28, 2026 at 12:45 am

    I believe the problem is this line:

    $.each(postsJSON, postsJSON1, function(i, post, post1) { 
    

    The generic iterator $.each() function only takes two parameters, the second of which is supposed to be a function. Similarly the callback function you provide is supposed to take two parameters.

    What is your intention as far as supplying two objects to iterate over at the same time? If you can describe your data structures and explain what you want to do I could make some suggestions. (Show your JSON…)

    UPDATE: OK, based on the question update both postsJSON and postsJSON1 are arrays. Given the way that you were trying to use both from inside the same function it appears that the elements within the arrays have a one-to-one relationship, that is, postsJSON[0] relates to postsJSON1[0], postsJSON[1] relates to postsJSON1[1], postsJSON[2] relates to postsJSON1[2], and so on and so forth.

    If that is the case the smallest possible change to your existing code to get it to work would be this:

    var postHandler = function(postsJSON, postsJSON1) {
       $.each(postsJSON, function(i, post) {
          var post1 = postsJSON1[i];
    
          // the rest of your code from inside your $.each() here
       });
    };
    

    That is, continue to use $.each(), but noting that it can only directly iterate over one array at a time use the provided index i to iterate over the other array in parallel by setting that up manually as the first line of the function.

    Or perhaps the more obvious way to do it is with a traditional for loop:

    var postHandler = function(postsJSON, postsJSON1) {
       var i, post, post1;
       for (i = 0; i < postsJSON.length; i++) {
          post = postsJSON[i];
          post1 = postsJSON1[i];
    
          // the rest of your code from inside your $.each() here
       }    
    };
    

    Either way will process both arrays in parallel. Obviously this assumes the arrays are the same length and that the items at any given index number will be the items that you want to relate to each other as mentioned above – if not then you will need to provide more detail about how the arrays are related.

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

Sidebar

Related Questions

What is wrong with this code. It does not give an error but no
This code always works, even in different browsers: function fooCheck() { alert(internalFoo()); // We
Why does this code give the error message IntelliSense: too many parameters for this
this code give me a syntax error ( syntax error, unexpected '=' ) in
Why does this code int (*g)(int); int (*h)(char); h = g; In C, give
I know how to do this... I'll give example code below. But I can't
This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a
This code does not seem to compile, I just need to write something to
I have this code: function beforemouseout() { if ($(this).val() == '') { $(this).val($(this).attr('title')); }
Can anyone comment out this code to give me a better idea of whats

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.