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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:07:48+00:00 2026-06-16T03:07:48+00:00

Hi am using a Jquery to call a php script. The php script is

  • 0

Hi am using a Jquery to call a php script. The php script is located at http://localhost:8080/getData.php and it accesses a MySql database.

I am using a tomcat server setup on my pc with the server address of localhost:8080

I have looked at the ajax response data.status and it is 0

I have read about cross domain requests and know that this should not be a problem if i am using JSONp.

Any help would be much appreciated.

The jquery part inside of my HTML i use to call an ajax function is below:

<script type="text/javascript">
$(document).ready(function() {
   $.ajax({
       type:'GET',
       url:'http://localhost/getData.php',
       datatype:'jsonp',
       timeout: 5000,
       success: function(data){
           //data loaded
           alert('loaded');

       },
       error: function(data){
           // error on loading data
           alert('error');        
       }
    });
});
</script>

The actual getData.php code is below:

<?php
header('Content-type: application/json');

$server = "127.0.0.1";
$username = "root";
$password = "";
$database = "deals";

$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);

$sql = "SELECT area_id, name AS area_name, sector AS area_sector FROM deals.areas ORDER BY name";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());

$records = array();

while($row = mysql_fetch_assoc($result)) {
    $records[] = $row;
}

mysql_close($con);

echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
?>
  • 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-16T03:07:50+00:00Added an answer on June 16, 2026 at 3:07 am

    I’m seeing three issues:

    1. Your PHP script is looking for a GET parameter called jsoncallback, but that’s not the name that jQuery sends by default, which is callback. Either change your PHP to use callback instead:

      // Here ----v
      echo $_GET['callback'] . '(' . json_encode($records) . ');';
      

      …or add this option to your ajax call to tell jQuery to use jsoncallback instead:

      jsonp: "jsoncallback",
      

      You can use the Network tab in your browser’s development tools to inspect the call and see what the query string looks like, to make sure they match up.

    2. You have a typo in your ajax options, you have datatype:'jsonp' instead of dataType:'jsonp' (the T in dataType must be upper case), so jQuery won’t have been trying to do a JSON-P call at all, it will have tried XHR.

    3. You’ve said in your question that the PHP page is at http://localhost:8080/getData.php, but the url you’ve given jQuery is http://localhost/getData.php (without the port).

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

Sidebar

Related Questions

I have a problem using ajax (jquery) and recursion. I call a php script
Im using jQuery to call PHP script with two parameters, from and to, which
I make a call to a php file using jquery's ajax function. It goes
My jQuery code (using ajax) request's data from a local php script (pgiproxy.php). This
I am using this jQuery.ajax: var url = http://client.my_url.com/test_get_account_data.php; jQuery.ajax({ type: GET, url: url,
I'm following the tutorial here: http://www.jotorres.com/2012/01/using-jquery-and-ajax-with-codeigniter/ For my view, I have: <script type=text/javascript src=<?php
I'm building a CMS with PHP/MySQL, and so far using jQuery to add sorting
I'm using jquery to send a shopping cart printed by javascript to PHP script
I'm using the script from http://webdeveloperplus.com/jquery/ajax-multiple-file-upload-form-using-jquery/ I modified the onComplete to add a link
I'm using an ajax call to call a php script which waits 40 seconds

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.