Why does my jQuery Ajax GET-request not receive a response from the server?

Engo

I am trying to let jQuery dynamically add html to my page. Unfortunately, I don't receive a response from my server. My JS code sends a GET request, which contains a parameter (bodypart). The server should return a response including the results from the database, but the response is empty.

What causes this problem?

JAVASCRIPT:

function getData() {

    var sPanelHeading = '<div class="col-lg-3"><div class="panel panel-default"><div class="panel-heading"><h3 class="panel-title">Symptomen van ' + bodypart + '</h3></div>';
    $( "#abc" ).append(sPanelHeading);
    $.ajax({
        url: 'controller.php',
        data: 'bodypart=Autism',
        dataType: 'json',
    }).done(function(data) {    
        $( "#abc" ).append('<div class="panel-body" style="overflow-y: scroll;"><span class="list-group-item"><b>Vaak voorkomende symptomen</b></span></div><div class="list-group">');

        for (var c in data) {
            $("#abc").append('<span class="list-group-item">');
            $("#abc").append(c);
            $("#abc").append('</span">');
        }  
    }).always(function(data) {
        console.log(data);
    });
}

PHP:

<?php
require_once( 'config.php' );

$bodypart = $_GET['bodypart'];

$sql = "SELECT c_name FROM condition WHERE c_name = '$bodypart'";
$result = $conn->query($sql);
$json_response = array();

if ($result->num_rows > 0) {
    while($row = mysql_fetch_assoc($query)) {
        $json_response[] = $row;
    }
    print json_encode($json_response);
}

$conn->close();

?>
Mohamed-Yousef

1st : instead of

data: 'bodypart=Autism',

use

data: {'bodypart':'Autism'},

2nd

echo json_encode($json_response);

Basics of $.ajax

$.ajax({
        url: 'controller.php',
        type: 'GET',
        data: {'bodypart':'Autism'},
        dataType: 'json',
        success : function(data){
           alert(data);
        }
    });

in php

<?php 
    $bodypart = $_GET['bodypart'];
    echo $bodypart;
?>

output should alert Autism .. if this Ok you can complete your stuff .. if something went wrong .. check your php file path

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get the response text from an AJAX request using jQuery

From Dev

how do i get a response from a jquery ajax request

From Dev

PHP does not receive parameters from Ajax request

From Dev

Why is my ajax request getting response 0?

From Dev

Server does not receive data from ajax call

From Dev

412 Server Response Code from $.ajax Request

From Dev

Why proxy server cannot receive response from server

From Dev

Postman extension get a response, but my jquery request not

From Dev

Response of ajax request is different on my local environment and my live server

From Dev

How to get the data response from ajax request?

From Dev

How to get the data response from ajax request?

From Dev

Why does response to my Java GET request have fewer headers than the same URL for Curl

From Dev

PHP does not receive my JSON sent by jQuery AJAX

From Dev

Incorrect response from the server anfter GET request

From Dev

why is jquery ajax not sending the data in get request

From Dev

jQuery: Ajax get request does not work with PHP

From Dev

Receive array from ajax request

From Dev

AJAX/Jquery - Get response from php file

From Dev

jQuery get response from ajax function

From Dev

Ajax jquery issue when I receive data from the server

From Dev

Why jQuery consider an 200 response Ajax request with empty content as fail()?

From Dev

Why does Buffer from my Observable not receive events?

From Dev

Using jquery in ajax request to get javascript response UJS

From Dev

Why am I getting a double response from this AJAX request?

From Dev

Why does my WEBrick server get killed?

From Dev

How to handle 204 response from ajax request in jquery

From Dev

403 Forbidden response from jQuery.ajax request with PhoneGap Desktop

From Dev

jQuery AJAX Request - Handle special characters in response from PHP page

From Dev

403 Forbidden response from jQuery.ajax request with PhoneGap Desktop

Related Related

  1. 1

    How to get the response text from an AJAX request using jQuery

  2. 2

    how do i get a response from a jquery ajax request

  3. 3

    PHP does not receive parameters from Ajax request

  4. 4

    Why is my ajax request getting response 0?

  5. 5

    Server does not receive data from ajax call

  6. 6

    412 Server Response Code from $.ajax Request

  7. 7

    Why proxy server cannot receive response from server

  8. 8

    Postman extension get a response, but my jquery request not

  9. 9

    Response of ajax request is different on my local environment and my live server

  10. 10

    How to get the data response from ajax request?

  11. 11

    How to get the data response from ajax request?

  12. 12

    Why does response to my Java GET request have fewer headers than the same URL for Curl

  13. 13

    PHP does not receive my JSON sent by jQuery AJAX

  14. 14

    Incorrect response from the server anfter GET request

  15. 15

    why is jquery ajax not sending the data in get request

  16. 16

    jQuery: Ajax get request does not work with PHP

  17. 17

    Receive array from ajax request

  18. 18

    AJAX/Jquery - Get response from php file

  19. 19

    jQuery get response from ajax function

  20. 20

    Ajax jquery issue when I receive data from the server

  21. 21

    Why jQuery consider an 200 response Ajax request with empty content as fail()?

  22. 22

    Why does Buffer from my Observable not receive events?

  23. 23

    Using jquery in ajax request to get javascript response UJS

  24. 24

    Why am I getting a double response from this AJAX request?

  25. 25

    Why does my WEBrick server get killed?

  26. 26

    How to handle 204 response from ajax request in jquery

  27. 27

    403 Forbidden response from jQuery.ajax request with PhoneGap Desktop

  28. 28

    jQuery AJAX Request - Handle special characters in response from PHP page

  29. 29

    403 Forbidden response from jQuery.ajax request with PhoneGap Desktop

HotTag

Archive