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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:33:12+00:00 2026-05-31T19:33:12+00:00

i am having a little trouble with the following ajax call; function question() {

  • 0

i am having a little trouble with the following ajax call;

function question()  {
//ajax call to fetch data from database
var course = "St.Andrews";
var dataString = "course=" + course;

$.ajax({
     type:  "GET",
     url:   "http://www.webaddress/fetch.php",
     datatype: "json",
     data: course,

     success: function(datas){
     console.log(datas);
     },
     error: function(XMLHttpRequest, textStatus, errorThrown){
     console.log("error:" + XMLHttpRequest.responsetext);
     }
     });
}

For some reason, i cannot get the fetched results to display. My php file that returns the results works fine if i navigate to it from the browser and i get the returned results in the valid format.

When i check the console log, i can see the params are correct and i get error:undefined.
Can anyone provide as to what i’m doing wrong, thanks.

Here is my php script;

<?php
//include databse details
require_once 'login.php';

//connect to database or return error
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("unable to connect to MYSQL:" . mysql_error());

//select database or return error
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());

if (isset($_GET['course'])) {

    $course = $_GET['course'];

    //set the character code
    mysql_query('SET CHARACTER SET utf8');

    //make the query
    $query = "SELECT * FROM questions WHERE course = '" . $course . "' ";
    $result = mysql_query($query) or die (mysql_error());

    if ($result !== false && mysql_num_rows($result) > 0)   {

        $row = mysql_fetch_array($result, MYSQL_ASSOC);

        $question = $row['question'];
        $answer = $row['answer'];
        $incorrect = $row['incorrectAnswer'];
        $difficulty = $row['difficulty'];

        //Json row
        $json = array ("question" => $question, "answer" => $answer, "incorrect" => $incorrect, "difficulty" => $difficulty);
    } else {
        //catch any errors
        $json = array("error" => "Mysql query error");
    }

    //set header for json data
    header("Content-Type: application/json", true);
    //return Json
    echo json_encode($json);
} else {
    echo "Needs course to advance dingbat";
}
  • 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-31T19:33:13+00:00Added an answer on May 31, 2026 at 7:33 pm

    The most probable reason is that you are calling that url from a different domain and that’s not possible using plain json for security reasons, you should use jsonp.

    To correct that:
    js

    var course = "St.Andrews";
    var dataString = {course: course, callback : "?"};
    
    $.ajax({
         type:  "GET",
         url:   "http://www.webaddress/fetch.php",
         datatype: "jsonp",
         data: course,
    
         success: function(datas){
         console.log(datas);
         },
         error: function(XMLHttpRequest, textStatus, errorThrown){
         console.log("error:" + XMLHttpRequest.responsetext);
         }
         });
    }
    

    php

    <?php header('content-type: application/javascript; charset=utf-8');
    
    $data = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
    
    echo $_GET['callback'] . '('.json_encode($data).')';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey basically just having a little trouble with the following, submitting a message from
I'm having a little bit of trouble saving data to a database. Basically, I
I am having a little bit of a trouble with the following: <script> $(document).ready(function()
I am having a little trouble understanding ServiceKnownType in WCF. Taken from this blog
I'm having a little trouble figuring out how to call the Parallel.ForEach with a
I'm having a little bit of trouble implementing the following method while handling the
I'm new to android programming and I'm having a little trouble with the following.
having a little trouble with a mapping for the following table setup currently: Shop
Hay, I'm having a little trouble. I have the following domain over at easily.co.uk
I am having a little trouble with the following php statement: if (!userIsLoggedIn()) {

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.