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

The Archive Base Latest Questions

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

A javascript function on a webpage requires data in the following format: // Javascript

  • 0

A javascript function on a webpage requires data in the following format:

// Javascript
var data = [
            {"AKey" : "AVal", "BKey" : "BVal"},
            {"AKey" : "AVal", "BKey" : "BVal"},
            {"AKey" : "AVal", "BKey" : "BVal"}
];

At the moment, this variable is hardcoded in the javascript file and everything works fine.
In the second step, I want to improve it by requesting the data from a server via jQuery’s ajax functionality instead of using the hardcoded variable, because of course, until now, the data is static.

So I put a text file on my server, it contains:

// textfile on server
[
            {"AKey" : "AVal", "BKey" : "BVal"},
            {"AKey" : "AVal", "BKey" : "BVal"},
            {"AKey" : "AVal", "BKey" : "BVal"}
];

And apart from that, a PHP script. the PHP script sets its content type to application/json and prints the textfile.

In Javascript, i tried something like this:

var jqxhr = $.getJSON("http://www.myserver.com/output.php", function() {
    alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });

jqxhr.complete(function(){ alert("second complete"); });

Unfortunately, I only get an “error” alert and the two complete alerts.

So I have two questions:

  • what’s wrong about the ajax call, maybe I should deliver the data in text/plain instead of application/json?
  • Apart from that Ajax stuff: as I mentioned above, a specific javascript function requires a variable/data in the format var data = [ { "A" : "B:}, { "A" : "B:}]; . Is the result of this query (if it would work..) the same format?

The only requirement is that I need both a success and an error handler, just a success handler is not enough.

Thank you

  • 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-30T00:18:30+00:00Added an answer on May 30, 2026 at 12:18 am

    you are accessing it through cross domain and it violates Same origin policy.

    follow this link to learn how to overcome this.

    see my answer on this question
    $.ajax call working fine in IE8 and Doesn't work in firefox and chrome browsers

    and your JSON should be in following format.

    [
       {"AKey" : "AVal", "BKey" : "BVal"},
       {"AKey" : "AVal","BKey" : "BVal"},
       {"AKey" : "AVal", "BKey" : "BVal"}
    ];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following JavaScript function to hide images on my webpage in the
I have a JavaScript function, pop_item . I have to call this from PHP,
I have Designed the Javascript function My.js it contains following code My.js function display(){
I have a JavaScript function that loads a flash movie into a webpage div
I have some VBA code that opens a webpage, then calls a javascript function
I have a javaScript function that loops through a variable number of iterations and
I need to create links on webpage which call a javascript function with different
I have found a javascript function that inverts colors on webpage: String javascript =
I have a webpage loaded in a UIWebView, and a javascript function of the
When I load a particular webpage, I'd like to call a Javascript function that

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.