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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:10:47+00:00 2026-06-16T22:10:47+00:00

I am trying to get a particular request from website by using variable in

  • 0

I am trying to get a particular request from website by using variable in the URL and AJAX to display JSON. It seems like everything is working but there is an error “TypeError: Cannot read property ‘length’ of undefined”. A debugger points to JQuery file and the line in my script ($.ajax.success).

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  alert('Query Variable ' + variable + ' not found');
}

$(document).ready(function () {

  var output = $('#news');
  var postid = getQueryVariable('id');

  $.ajax({
    url: 'http://www.domain.pro/api/get_post/?post_id=' + postid + '&post_type=news',
    async: false,
    callback: 'callback',
    crossDomain: true,
    contentType: 'application/json; charset=utf-8',
    type: 'POST',
    dataType: 'jsonp',
    timeout: 5000,
    success: function (data, status) {
       $.each(data.posts, function (i, item) {
        var news = '<div>' + item.title + '</div><div>' + item.content + '</div><hr/>';

        output.append(news);


      });
    },
    error: function () {
      output.text('There was an error loading the data.');
    }
  });
})

Could you please help me to sort this out? Really appreciate your halp.

  • 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-16T22:10:48+00:00Added an answer on June 16, 2026 at 10:10 pm

    You should validate your data before performing operations on it:

    UPDATED

     $.ajax({
                url: 'http://www.domain.pro/api/get_post/?post_id=' + postid + '&post_type=news',
                async: false,
                callback: 'callback',
                crossDomain: true,
                contentType: 'application/json; charset=utf-8',
                type: 'POST',
                dataType: 'jsonp',
                timeout: 5000,
                success: function (data, status) {
                   if(data != undefined && data.post != undefined){
                     $('#news').append('<div>' + data.post.title + '</div><div>' + data.post.content + '</div><hr/>');
                    }
                },
                error: function () {
                  output.html('<h1 class="error">There was an error loading the data.</h2>');
                }
              });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My website is suffering from an apparent bot which GETs a particular URL 5
I am trying to get access to all the endpoints that a particular contact
I'm trying to get meta tag information for each page on a particular site,
I am trying to get started in testing ActiveAdmin, in particular I need to
I'm messing with core.time.Duration s - in particular, I'm trying to properly get number
I'm trying to duplicate a particular entry in the form. I get all the
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I am trying get Struts 2 and Tiles to work and I am using

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.