Unable to set value to select2 drop down - html

To do: Add a city under a country. Then attempt to edit the city record.
I have: City name as a textbox and Country as a Select2 dropdown in the bootstrap modal which is accessed using a Edit button on the page.
Issue - I am unable to set the value of the country in the select2 dropdown retrieved from database using ajax call. I tried all possible combinations to set value. I am able to set value if its a normal dropdown box, but not when it is a select2 box.
This is the html of the select 2 box in the bootstrap
<div class="modal fade" id="edit">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick = "location.reload(true);">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title"><b>Edit City</b></h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="POST" action="city_edit.php">
<input type="hidden" class="catid" name="id">
<input type="text" name="cityid" id="cityid" hidden>
<div class="form-group">
<label for="name" class="col-sm-3 control-label">City</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="cityname" name="cityname" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Country</label>
<div class="col-md-8">
<select data-plugin-selectTwo class="form-control" name="country" id="country" required>
<option value = "">Select Country</option>
<?php
$conn = $pdo->open();
try{
$stmt = $conn->prepare("SELECT country_id,country FROM country where del_flg = 'N' and status = 1");
$stmt->execute();
foreach($stmt as $row)
{
$countryid = $row['country_id'];
$country = $row['country'];
echo "
<option value='".$countryid."'>".$country."</option>
";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
$pdo->close();
?>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-flat pull-left" data-dismiss="modal" onclick = "location.reload(true);"><i class="fa fa-close"></i> Close</button>
<button type="submit" class="btn btn-success btn-flat" name="edit"><i class="fa fa-check-square-o"></i> Update</button>
</form>
</div>
</div>
</div>
JQUERY:
$(document).ready(function() {
$('.js-example-basic-single').select2();
});
$(document).on('click', '.edit', function(e){
e.preventDefault();
$('#edit').modal('show');
var id = $(this).data('id');
getRow(id);
});
function getRow(id){
$.ajax({
type: 'POST',
url: 'city_row.php',
data: {id:id},
dataType: 'json',
success: function(response){
$("input[type=text][name=cityname]").val(response.city);
$('#country').val("1").trigger("change");
}
});
}

inside your ajax, you add option following your country like that
(i suppose response.country is country, either you adapt):
function(response){
var idx=1;
countries=[];
for(var i = 0;i< response.length;i++){
if(countries.includes(response.country) continue;//country already in option?
countries.push(response.country);//i keep the country in array
$("#country").append(new Option(response.country, idx++));//add option to select
}
$("#country").select2();//initialize the select2
}

Related

Make button to be disabled initially, and enable if length of input is 10 in Angular

I have a requirement where I have to keep the button to be disabled initially and enable it only when the length of my input is 10.
<div class="form-group">
<label for="MSISDN_Value" class="m-r-10">MSISDN:</label>
<input type="number"
onkeyPress="if(this.value.length === 10) return false;"
[(ngModel)]="MSISDN_Value"
id="MSISDN_Value"
name="MSISDN_Value"
class="form-control display-inline-block width70p m-b-5">
</div>
<div class="form-group">
<button class="btn btn-primary m-l-65" type="submit"
[disabled]="true">Search</button>
</div>
I tried [disabled] = "MSISDN_Value.length !== 10" but it did not work, there are many solutions that disable buttons, but I couldn't find any solution which enables buttons in Angular5.
Hii the problem is you are checking integer value with === operator which is returning false. see my below code.
<div class="form-group">
<label for="MSISDN_Value" class="m-r-10">MSISDN:</label>
<input type="number"
#num
max=10
(change)="toggle2($event)"
id="MSISDN_Value"
name="MSISDN_Value"
class="form-control display-inline-block width70p m-b-5">
</div>
<div class="form-group">
<button class="btn btn-primary m-l-65" type="submit"
[disabled]="this.num.value==10?false:true">Search{{this.num.value===10}}</button>
</div>
//.ts file
toggle2(event){
console.log(event.target.value)
}
After searching, I took the help of events and used (input) function binding and fired an event on even.target.value changes to toggle [isDisabled]
<div class="form-group">
<label for="MSISDN_Value" class="m-r-10">ISMSDN/IMEI:</label>
<input type="number" onkeyPress="if(this.value.length === 10) return false;" (input)="onSearchChanges($event.target.value)" [(ngModel)]="MSISDN_Value" id="MSISDN_Value" name="MSISDN_Value" class="form-control display-inline-block width59p m-b-5">
</div>
<div class="form-group">
<button class="btn btn-primary m-l-96" type="submit" [disabled]="searchDisabled">Search</button>
</div>
component.ts file
onSearchChanges(value) {
if(value.length === 10){
this.searchDisabled = false;
} else{
this.searchDisabled = true;
}
}

The form in my pop-pup window fails to submit the inserted data in Laravel

I'm trying to submit data using a pop-pup form but my submit button just closes the windows instead of saving all the data into my data base.
Everything seems to be in order but I have the impression that the form cannot read the lines of code contained in my controller
Here my codes
<div class="modal" id="exampleModalLong" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><b>ADD A NEW CLIENT</b></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i data-feather="x"></i>
</button>
</div>
<div class="modal-body">
<form action="{{ route('finance.store') }}" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<label>Select an existing user from the database. </label>
<div class="row">
<div class="form-group col-xs-5">
<select id="Clients" class="choices form-select" title="Selectionner"
name="user_id">
<optgroup label="{{ count($Users) }} clients retrouvés">
<option value="" disabled selected>-- choisir --</option>
#foreach($Users as $User)
<option value="{{ $User->id }}">{{ $User->fullname }}</option>
#endforeach
</optgroup>
</select>
</div>
<label>Profession</label>
<div class="form-group">
<select class="choices form-select" title="Selectionner"
name="profession_id">
<option value="" disabled selected>-- choisir --</option>
#foreach($Professions as $Profession)
<option value="{{ $Profession->id }}">{{ $Profession->name }}</option>
#endforeach
</select>
</div>
<label>Phone</label>
<div class="form-group">
<input type="text" name="phone" placeholder="+243 " class="form-control">
</div>
<label>NID Type</label>
<div class="form-group">
<input type="text" name="nid_type" class="form-control">
</div>
<label>NID Photocopy</label>
<div class="row">
<div class="col-lg-2 col-xs-2">
<div class="form-group">
<img id="outputs" style="width:45px;background-color: whitesmoke;
border:1px solid #bbb;height:45px;border-radius: 2px" >
</div>
</div>
<div class="col-lg-10 col-xs-10">
<div class="form-group">
<div class="form-file">
<script type="text/javascript">
function previewImg(event) {
var outputs = document.getElementById('outputs');
outputs.src = URL.createObjectURL(event.target.files[0]);
}
</script>
<input type="file" name="nid_photocopie" accept=".png, .jpeg, .jpg"
class="form-control" id="clientImges"
onchange="return previewImg(event)">
</div>
</div>
</div>
</div>
<label>Profile Image</label>
<hr>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<img id="output" style="width:50px;height:50px;border-radius: 50px " >
</div>
</div>
<div class="col-md-10">
<div class="form-group">
<div class="form-file">
<script type="text/javascript">
function previewImage(event) {
var output = document.getElementById('output');
output.src = URL.createObjectURL(event.target.files[0]);
}
</script>
<input type="file" name="image" accept=".png, .jpeg, .jpg"
class="form-file-input" id="clientImgz"
onchange="return previewImage(event)">
<label class="form-file-label" for="clientImgz">
<span class="form-file-text">Choose image...</span>
<span class="form-file-button "><i data-feather="upload"></i></span>
</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light-secondary" data-dismiss="modal">
<i class="bx bx-x d-block d-sm-none"></i>
<span class="d-none d-sm-block">Close</span>
</button>
<button type="submit" class="btn btn-outline-secondary ml-1" >
<i class="bx bx-check d-block d-sm-none"></i>
<span class="d-none d-sm-block">Submit</span>
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
HERE IS MY CONTROLLER
public function storeProfile(Request $request)
{
$this->validate($request, [
'user_id' => 'required',
'profession_id'=> 'required',
'nid_type'=> 'required',
'nid_photocopie'=> 'required',
]);
$slug = str_slug($request['fullname']);
$image = $request->file('image');
$image3 = $request->file('nid_photocopie');
//INSERTS PROFILE IMAGE
if (isset($image))
{
$image = $request->file('image');
$currentData = Carbon::now()->toDateString();
$fileToStore = $slug .'-'. $currentData .'-'. uniqid() .'.'. $image->getClientOriginalExtension();
if(!file_exists('uploads/MicroCredit/ClientImage'))
{
mkdir('uploads/ClientImage', 0777 , true);
}
$image->move('uploads/ClientImage',$fileToStore);
}
else {
$fileToStore = 'default.png';
}
//INSERT ID PHOTOCOPIE
if (isset($image3))
{
$image3 = $request->file('nid_photocopie');
$currentData = Carbon::now()->toDateString();
$IdToStore = $slug .'-'. $currentData .'-'. uniqid() .'.'. $image3->getClientOriginalExtension();
if(!file_exists('uploads/MicroCredit/IDs'))
{
mkdir('uploads/IDs', 0777 , true);
}
$image3->move('uploads/IDs',$IdToStore);
}
else {
$IdToStore = 'default.png';
}
$CredNew = new Client();
$CredNew->user_id = $request->user_id;
$CredNew->profession_id = $request->profession_id;
$CredNew->nid_type = $request->nid_type;
$CredNew->nid_photocopie = $IdToStore;
$CredNew->image = $fileToStore;
$CredNew->slug = $slug;
$CredNew->save();
return redirect(route('/bienvenue'));
}
HERE MY ROUTES
// ========= FINANCE - CLIENTS ======== //
Route::get('/finance/creditor', [FinanceController::class,'indexCreditor'])
->name('finance.creditor');
Route::post('/finance/store', [FinanceController::class,'store'])
->name('finance.store');
Route::post('/finance/{id}/update', [FinanceController::class,'update'])
->name('finance.update');
Route::delete('/finance/{id}/destroy', [FinanceController::class,'destroy'])
->name('finance.destroy');
HERE MY MODEL
public function storeProfile(Request $request)
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Client extends Model
{
use HasFactory;
protected $with = ['Userz'];
protected $fillable = [
'user_id',
'profession_id',
'nid_type',
'nid_photocopie',
'image',
'slug'
];
public function profesn()
{
return $this->belongsTo(Profession::class,'profession_id');
}
public function Userz()
{
return $this->belongsTo(User::class,'user_id');
}
public function getRouteKeyName()
{
return 'slug';
}
}
HERE'S MY MIGRATIONS
class CreateCreditorsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('clients', function (Blueprint $table) {
$table->id();
$table->integer('user_id');
$table->integer('profession_id');
$table->string('nid_type');
$table->string('nid_photocopie');
$table->string('image')->nullable();
$table->string('slug')->nullable();
$table->timestamps();
});
}
By using dd(), I was able to see which input field was causing the popup modal not to submit the data. Thanks for everyone who reached out!
dd($CredNew);

I cannot submit angular reactive form in a ngb modal Angular 7

I am trying to create a form in a NgbModal, I can open an initialize the form however when I press submit button, nothing happens.
Here is HTML code;
<ng-template #content let-c="close" let-d="dismiss">
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">Give your feedback</h4>
</div>
<form [formGroup]="addForm" (ngSubmit)="onSubmit()">
<div class="modal-body">
<div class="form-group">
<label>Title</label>
<input type="text" formControlName="title" class="form-control" [ngClass]="{ 'is-invalid': submitted && addForm.controls.title.errors }" />
<div *ngIf="submitted && addForm.controls.title.errors" class="invalid-feedback">
<div *ngIf=" addForm.controls.title.errors">* Title is required</div>
</div>
</div>
<div class="form-group">
<label>Comment</label>
<textarea type="text" rows="4" cols="50" formControlName="text" class="form-control" [ngClass]="{ 'is-invalid': submitted && addForm.controls.text.errors }"></textarea>
<div *ngIf="submitted && addForm.controls.text.errors" class="invalid-feedback">
<div *ngIf=" addForm.controls.text.errors">* Comment is required</div>
</div>
</div>
<div class="form-group">
<label>Rate</label><br>
<ngb-rating formControlName="rate" max="5" [starTemplate]="rate">
</ngb-rating>
</div>
</div>
<div class="modal-footer">
<button style="margin-left: 5px" type="submit" class="btn btn-success pull-right">Save</button>
<button type="button" class="btn btn-outline-danger pull-right" (click)="c('cancelled')">Cancel</button>
</div>
</form>
</ng-template>
<ng-template #rate let-fill="fill" let-index="index">
<span class="star" [class.filled]="fill === 100">★</span>
</ng-template>
<ng-template #rate let-fill="fill" let-index="index">
<span class="star" [class.filled]="fill === 100">★</span>
</ng-template>
<button *ngIf="authService.currentUserValue" type="button" style="height: 50px" (click)="open(content)" class="btn btn-outline-primary pull-right" data-toggle="modal">
give your feedback
</button>
My open button works fine and also I can close modal, but somehow save is not working. Additionally my onSubmit method is like;
onSubmit() {
this.submitted = true;
const data = {
productId:this.currentProduct.productId,
userId: this.authService.currentUserValue.userId,
title: this.addForm.controls.title.value,
text: this.addForm.controls.text.value,
rating: this.addForm.controls.rating.value,
};
this.loading = true;
this.commentService.addComment(data).subscribe(
data => {
this.success = true;
this.router.navigate(['/']);
},
error => {
this.error = error;
this.loading = false;
}
)
}
No error is thrown or no action happens, clicking is not working. How can I fix this?
Your component doesn't know which modal to close. You need to pass the NgbModal reference to the submission function.
<form [formGroup]="addForm" (ngSubmit)="onSubmit(content)">
'content' refers to the template reference of the modal.
onSubmit(modal: NgbModal) {
modal.dismiss(); // Add wherever you need
}
And just as a heads up, if you...
<form [formGroup]="addForm" (ngSubmit)="onSubmit()" #f="ngForm"> /* Last attribute added */
and then create add a ViewChild before the constructor...
#ViewChild('f') ngForm: NgForm;
you'll be able to access ngForm's submission status by this.ngForm.submitted rather then setting them yourself manually. Angular docs for NgForm

Create a form for each checkbox in the foreach loop with Laravel

I am trying to create a form for each item (checkboxes) inside the foreach item and save the item to the database whenever the item is checked.
My problem is even I created a form inside the foreach loop, so every item has its own form; when I do inspect the element I find that all item are included in the same form and only the first checked element is saved to the database
here is my code in order to create a form for each item
#foreach($sessions as $session)
<h1> {{$session->quarter}} {{$session->year}} </h1>
#foreach($courses as $course)
#if($session->id== $course->quarterIDFk)
<form action="{{route('course.add')}}" method="POST" id="report" >
<div class="aa">
<div class="dd">
<button >
<section class="checkboxFour">
<input hidden type="checkbox" id="{{ $course->id}}" name="{{$course->id}}" onclick="showComboBox(id)"; />
<label for="{{ $course->id}}"></label>
</section>
</button>
<label class="class_name" value ="{{ $course->id}}" >{{ $course->courseNumber}}</label>
<input hidden type="number" value="{{ $course->id}}" name ="course"/>
</div>
<div class="select-style" id="check{{ $course->id}}" hidden >
<select name="a">
<option value="" selected disabled hidden>Taken on </option>
<option value="Summer">Summer</option>
<option value="Fall">Fall</option>
<option value="Winter">Winter</option>
<option value="Spring">Spring</option>
</select>
</div>
</div>
<!-- The Modal -->
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modal Heading</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
Modal body..
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal" >Close</button>
<button type="button" class="btn btn-success" onclick="hideComboBox({{ $course->id}})" data-dismiss="modal">Yes</button>
</div>
</div>
</div>
</div>
#endif
#endforeach
</from>
#endforeach
and i used this ajax script so the page doesn't load whenener i click the submit button
<script>
$(function () {
$('#report').submit(function (e) {
e.preventDefault() // prevent the form from 'submitting'
var url = e.target.action // get the target
var formData = $(this).serialize() // get form data
$.post(url, formData, function (response) { // send; response.data will be what is returned
// alert('report sent')
})
})
})
</script>
and here is the controller function to store checked items to the database
public function store(Request $request)
{
if(!empty($request->a))
{
$claass = new Taken_classes ;
$claass->idUser = Auth::user()->id ;
$claass->idCourse = $request->course;
// $claass->idCourse = 12;
$claass->taken_session = $request->a;
$claass->save() ; }
I expect to save each checked item to the database but just the first checked item is saved

Web application using the Slim API. I'm trying to get data from my SQL database to populate a modal when the edit link is clicked in the table

Whilst debugging; the id for each row is found when the edit button is clicked but it seems to get stuck at that point. The data for the said row will not populate the modal. I would appreciate any help at all! Here is a picture in chrome. I have exhausted all of my ideas. I do have an error for localhost failed to load resource for an image folder, could this be causing conflict? I don't see how.
HTML
<div class="tab-pane" id="admin">
<br>
<div class="container">
<table id="admin_table" class="display">
<thead>
<tr>
<th>Title</th>
<th>Genre</th>
<th>Platform</th>
<th>Score Phrase</th>
<th>Score</th>
<th>Release Year</th>
<th>Release Month</th>
<th>Release Day</th>
<th>Editors Choice</th>
<th>Edit</th>
<th>x</th>
</tr>
<tbody id="admin_table_body">
</tbody>
</table>
</div> <br><br><br><br>
</div>
</div>
>Modal
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Edit</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post">
<div class="form-group">
<label class="col-sm-4 control-label"><strong>ID:</strong></label>
<input type="text" style="height:32px;" name="id" id="id" disabled/>
<label for="id" class="error"></label>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><strong>Title:</strong></label>
<input type="text" style="height:32px;" id="title" name="title"/>
<label for="title" class="error" ></label>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><strong>Genre:</strong></label>
<input type="text" style="height:32px;" id="genre" name="genre"/>
<label for="genre" class="error" ></label>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><strong>Platform:</strong></label>
<input type="text" style="height:32px;" id="platform" name="platform"/>
<label for="platform" class="error" ></label>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><strong>Score:</strong></label>
<input type="text" id="score" name="score" style="height:32px;"/>
<label for="score" class="error"></label>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><strong>Score Phrase:</strong></label>
<input type="text" id="score_phrase" name="score_phrase" style="height:32px;"/>
<label for="score_phrase" class="error"></label>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><strong>Release Year:</strong></label>
<input type="text" id="release_year" name="release_year" style="height:32px;"/>
<label for="release_year" class="error"></label>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><strong>Release Month:</strong></label>
<textarea id="release_month" name="release_month" style="height:32px;"></textarea>
<label for="release_month" class="error"></label>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><strong>Release Day:</strong></label>
<textarea id="release_day" name="release_day" style="height:32px;"></textarea>
<label for="release_day" class="error"></label>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><strong>Editors Choice:</strong></label>
<textarea id="editors_choice" name="editors_choice" style="height:32px;"></textarea>
<label for="editors_choice" class="error"></label>
</div>
</form>
</div>
Main.js
var rootURL ="http://localhost:4006/GamesAPI/api/games";
var currentGame;
//when the DOM is ready
$(document).ready(function(){
findAll();
//findById();
$(document).on("click","#admin_table_body a",function(){findById(this.id);});
// $(document).on("click","#addButton",function(){addGame();});
// $(document).on("click","#deleteButton",function(){deleteGame();});
});
var findAll=function(){
console.log('findAll');
$.ajax({
type: 'GET',
url: rootURL,
dataType: "json", // data type of response
success: renderList
});
};
var findById = function(id)
{
console.log('findById: '+id);
$.ajax({
type: 'GET',
url: rootURL + '/' + id,
dataType: "json",
//Gets stuck here
success: function(data){
//$('#btnDelete').show();
console.log('findById success: ' +data.title);
currentGame = data;
renderDetails(currentGame);
}
});
};
function renderList(data){
list = data.games;
console.log("renderList");
$('#admin_table_body tr').remove();
$.each(list, function(index, games){
$('#admin_table_body').append('<tr><td>' +games.title+'</td><td>'+games.genre+'</td><td>'
+games.platform+'</td><td>' +games.score_phrase+'</td><td>'
+games.score+'</td><td>'+games.release_year+'</td><td>'+games.release_month+'</td><td>'
+games.release_day+'</td><td>'+games.editors_choice+'</td><td>\n\
Edit</td>\n\
<td id="'+games.id+'"><button type="button" id="deleteButton" class="btn btn-success">Delete</button></td></tr>');
});
$('#admin_table').DataTable();
// $('gameList').append('<div class="row">');
//The rest of this function is to populate a different client page
output='<div class="row">';
$.each(list, function(index,games){
var img="pics/"+games.picture;
output+=('<div class="col-sm-6 col-md-4 col-lg-3"><div class="card"><img src='+'"'+img+'"'+
'height="150"><p>Title: '+games.title+'</p><p>Genre: '+games.genre+'</p><p>Platform: '+games.platform+
'</p><p>Score: '+games.score+' '+games.score_phrase+'</p></div></div>');
// $('#gameList').append('<div class="col-sm-6 col-md-4 col-lg-3"><div class="card">'+game.title+'</div></div>');
});
// $('#gameList').append('</div>');
output+='</div>';
$('#productList').append(output);
};
var renderDetails = function(games)
{
$('#id').val(games.id);
$('#title').val(games.title);
$('#url').val(games.url);
$('#platform').val(games.platform);
$('#score').val(games.score);
$('#score_phrase').val(games.score_phrase);
$('#genre').val(games.genre);
$('#pic').attr('src', 'pics/' + games.picture);
$('#editors_choice').val(games.editors_choice);
$('#release_year').val(games.release_year);
$('#release_month').val(games.release_month);
$('#release_day').val(games.release_day);
};
DatabaseMethod.php
function getGame($id) {
$query = "SELECT * FROM games WHERE id = '$id'";
try {
global $db;
$games = $db->query($query);
$game = $games->fetch(PDO::FETCH_ASSOC);
header("Content-Type: application/json", true);
echo $query;
echo json_encode($game);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
Your server-side PHP method is outputting data which is not valid JSON.
Remove
echo $query;
from your code, since it's just left over from debugging. This is preventing jQuery from seeing the whole response as JSON and parsing it accordingly.