0

I have an unknown situation that AJAX request does not reach to the PHP server.
There is no error code in the Chrome browser, but it's not reaching the PHP GET method.

In my code

function GetLectureData(SID){
    $.ajax({
        url: "test.php",
        dataType: "jsonp",
        jsonpCallback: 'callback',
        data: {"SID_key": SID},
        Type: 'GET',
        success: function(data) {
            console.log('DB정보 접근성공- ', data);
            if(data != null)    {
                for(var i=0; i<data.length;i++)
                {
                    var flags=true;
                    lectrueInfo=data[i].classroom.split('-');
                    Lecture[i] = lectrueInfo[1];
                    Lecture[i] = Lecture[i].slice(1,4)+"호";
                    console.log(Lecture[i]+"  "+count);
                    count++;
                    if(typeof Lecture[i]== "undefined")
                    {
                        break;
                    }
                    for(var j=0;j<i; j++)
                    {
                        if(Lecture[i]==Lecture[j])
                        {
                            flags = false;
                        }
                    }
                    if(flags == true)
                    {
                       Create(Lecture[i]);
                    }

                }
            }
        },
        error: function(xhr) {
            console.log('실패 - ', xhr);
        }
    });
}
<?php

header('Content-Type: application/javascript;charset=UTF-8');

$user = 'hyumini';
$pw = 'hyu(e)mini';
$db = 'hyumini';
$host ='localhost';
$port = 3306;
$table = 'LectureSchedule';

$my_db = new mysqli($host,$user,$pw,$db,$port);

mysqli_query($my_db,"set names utf8");
if ( mysqli_connect_errno() ) {
        echo mysqli_connect_errno();
        exit;
}
$q=$_GET["SID_key"];

$callback = $_REQUEST['callback'];
$return_array = array();
$count = 0;

$rs = mysqli_query($my_db, "select DISTINCT  LectureSchedule.classroom
from ConnectLecture JOIN LectureSchedule 
ON ConnectLecture.SID = $q AND ConnectLecture.lectureID = LectureSchedule.lectureID");


while($data = mysqli_fetch_array($rs))
{
 $array[] = $data;
}


$my_db->close();

$json_val = json_encode($array);


echo $callback."(".$json_val.")";
?>

this is my result
pending situation

I'm really wondering why this is occurring in this situation.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
  • You are passing data as if you're attempting to POST, try passing as a URL query string i.e `data: "SID_key=value"`, also, declare type before data. – Kisaragi Jun 21 '16 at 12:36
  • You're specifying `callback` as your jsonpCallback, but I don't see a function named `callback` defined in the code you posted. – bflemi3 Jun 21 '16 at 12:41
  • @Kisaragi if you're specifying `GET` as your type then data will be appended to the query string. And the order in which you declare the properties of the ajax options does not matter. – bflemi3 Jun 21 '16 at 12:43
  • see the example code in your anwer becaus im beginner coder – Hyung Lak Kim Jun 21 '16 at 12:51
  • i want to get new solution in this comment not understand about answer – Hyung Lak Kim Jun 21 '16 at 13:45

1 Answers1

2

Click on that request in your result you show in network panel, the connection established and if request pending cause of Time To First Byte (TTFB)-> it means problem in php code,

Else if connection not established firstly then this request is in stole mode. which means few more request is in pending before this request. so this request will response after previous request complete.

Parth Patel
  • 521
  • 2
  • 12