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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:56:43+00:00 2026-05-31T16:56:43+00:00

I created a php file to return data encoded with JSON and then used

  • 0

I created a php file to return data encoded with JSON and then used getJSON to read it. I am attempting to get info from one source and distribute it to multiple areas. I have changed the content-type also allowing all access with headers. At this point I am stuck. Any ideas how to get this working?

PHP

header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');
header('Access-Control-Allow-Origin: *');

$search_terms = curlData();
$json = array("term" => $search_term);   
echo $_GET['callback'] . "(" . json_encode($json) . ");";

the output for this php file is as follows:

({"term":"sandwich city"});

Here is the jQuery I am using to retrieve the json info

$.getJSON("http://MYWEBSITE.com/terms.php?callback", function(data) {
    alert(data);
});

​

  • 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-31T16:56:44+00:00Added an answer on May 31, 2026 at 4:56 pm

    ({"term":"sandwich city"}); is not valid JSONP. You are missing the function name.

    Add =? to your URL, so that jQuery automatically generates a function to handle the response:

    http://MYWEBSITE.com/terms.php?callback=?
    

    From the documentation:

    If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.


    Btw, if you send JSONP as response, setting the content type of the response to application/json is not correct. The response is simply JavaScript.

    Furthermore, as you specified the Access-Control-Allow-Origin header, you don’t have to use JSONP at all, you can make a normal AJAX call and return JSON.

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

Sidebar

Related Questions

I am trying to make HTML code inside my PHP file and return from
I am attempting to use JSONP to return an array from PHP to JavaScript.
How to manually create Friendly URLs? (PHP) So I have created simple php file
I created an error500.php file in web/errors/ and would now like to test it.
I have created PHP GD image for captcha, file called image.php each time it
I created a jQuery function that calls on a PHP server-side file that pulls
I created a file download script in PHP, it works, but web browsers report
Hi I created two file to switch my forum (Language Chinese and English) enForum.php
I have a filelist.txt file and I created a file called clear.php to clear
I have a html page that calls a php object to get some data

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.