filtering mysql results which are dynamically loaded

I have 3 pages

  • index.php
  • fetch_pages.php
  • script.js

and a list of artists, the get page fetches the results and the script.js asks for more to dynamically load it into index php, but it loads all of the artists.

loading all the artists dynamically took me a long time and I didn’t fully understand all of the code I’ve copied to achieve this, but now as I don’t fully understand it it’s hard to play around with it, but I believe that I’ll learn along the way

what I want to do is instead of loading all the artists to load the results according to user input (if he clicks photographers load photographers, if he enters a search term to look for results LIKE what he searched for)

What I’ve tried is the $_GET method, but it posts the searchterm in the url of index.php, and when I try to use $_GET in fetch_pages.php it doesn’t see the parameter.

my question is how to $_GET the url parameter from index.php to fetch_pages.php

below is my code


// including the config file
<!DOCTYPE html>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" href="" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  <link href="" rel="stylesheet">
  <link href="//" rel="stylesheet">
  <link rel="stylesheet" href="css/style.css" />

JQuery Ajax 500 (Internal Server Error)

I’m utilizing the jquery library to make an ajax call to a php file. Everything was working fine when the path was relative like this:


But when I change the path like this:


I’m getting this error from the console:

jquery-2.2.3.min.js:4 POST http://localhost/SchoolMate/includes/ajax/fetch_term_grades.php 500 (Internal Server Error)

enter image description here

This is my ajax code:

            //$('table').attr('id', 'dataTable');  


Source: stackoverflow-php

pass array values from AJAx to PHP

Hi i am facing some issues. I am trying to insert array in mysql using ajax and php but its not working following is my code:


 <input type="text" class="form-control" name="invoice" id="invoice"   placeholder="piece">
 <input type="text" class="form-control" name="pieces[]" id="pieces" placeholder="Qty">

i want to pass fields from ajax to php. I am using following code in ajax.

var inv = $("#invoice").val();
var pieces = $("#pieces").val();


    type: "POST",
    url: "query.php",
    data: "piece="+pieces+"&inv="+inv,
    success: function(data){



following is the PHP code.

$piece = $_POST[piece];
foreach ($piece as $key=>$value)
$query = mysql_query(insert into items values ('$value','$_POST[inv]');

Source: stackoverflow-php

JS continue after multiple .load()-functions done

I’m having a problem with an asynchronous JS function. Well I have a function which inserts elements one by one. This works. But I would like to continue after all .load()-functions are done.

The way I’ve implemented the Deferred() part is obviously wrong but I have no clue how to achieve this.

Note: I have simplified the code for a better clarity.

var d = new jQuery.Deferred();
var i = index;
function loadView() {
    if(i > -1 && i < array.length) {
        if(!jQuery.contains(document.documentElement, $(selector)[0])) {
            /* do stuff here */
            panel.load(myPHPfile, function() {
                if(i < array.length) {

jQuery.when(d).then(function() {
    /* when all elements are insert, do something */

I am thankful for any help!

Source: stackoverflow-javascript

Post files and input throught ajax formData

I need to post both files and input value throught one ajax call here is the code that am using actually, the upload is actually working but the problem is when i submit the form i get two rows(see pic) image here
because i am posting two ajax calls to the same php page, so if anyone can help to post only one ajajx call with the both values.

<form  method="post" id="form_upload" enctype="multipart/form-data">
  <input type="file" name="user_upload" id="mydrop" />
  <input type="hidden" id="userID" value="1" /> 


var form_upload = $("#form_upload").serialize();
                    data: form_upload,
                     type: 'POST',
                     url: 'upload.php',
                     success : function(data){
                    var file_data = $('#mydrop').prop('files')[0];
                    var form_data = new FormData();                  
                    form_data.append('file', file_data);
                                url: 'upload.php', 
                                dataType: 'text',
                                cache: false,
                                contentType: false,
                                processData: false,
                                data: form_data,                         
                                type: 'post',



    $dbhost = "localhost";
    $dbuser = "root";
    $dbpass = "";
    $dbname = "494815";

    try {

        $dbcon = new PDO("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
        $dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $targetDir = "users_upload/";
        $temp = explode(".", $_FILES["file"]["name"]);
        $newfilename = round(microtime(true)) . '.' . end($temp);
        $targetFile = $targetDir.$newfilename;
        if move_uploaded_file($_FILES['file']['tmp_name'],$targetFile);
            $user_id = $_POST['user_id'];
            $stmt = $dbcon->prepare("INSERT INTO users_upload (user_id, file_name, file_date) VALUES('$user_id', '".$newfilename."','".date("Y-m-d H:i:s")."')");
    catch(PDOException $e)
            echo $e->getMessage();

    $conn = null;

Source: stackoverflow-javascript

second file downloads not first

I’ve got a problem when i’m dragging over my upload zone (drag n drop). For example, I have two files 1.csv, 2.csv and when i’m trying to upload this two files, only second uploads(2.csv). I want to upload just first and set permission to uploading only first file if two or more has chosen. Please help;(

    dropContainer.ondragover = dropContainer.ondragenter = function(evt) {

dropContainer.ondrop = function(evt) {
    fileInput.files = evt.dataTransfer.files;


Source: stackoverflow-javascript

Unable to convert Javascript object to Java Model

My Spring controller and client side Javascript code are as follows and for some reason the Javascript object is unable to reach the Spring controller in the Object form. My Controller code is as follows:

@RequestMapping(value = "/addRating", method = RequestMethod.POST, headers = "Accept=application/json")
public EmployeeRating addRating(@ModelAttribute("employeeRating") EmployeeRating employeeRating) {  

    return employeeRating;

My Javascript code below:

          url: 'https://myrestURL/addRating',
          type: 'POST',
          dataType: 'json',
          data: {
              'name': 'Name',
              'rating': '1'
          contentType: 'application/json; charset=utf-8',
          success: function (result) {
             // CallBack(result);
             window.alert("Result: " + result);
          error: function (error) {
              window.alert("Error: " + error);

The EmployeeRating object in Java has id, name and rating fields so there’s no mismatch.

Source: stackoverflow-javascript

PHP ajax image upload multiplies

Spent whole night with this script
but cant fix the bug.
it would be better if anyone can help me on this

say if i select an image and click upload it uploads current image file
then if i select another image and click upload it upload 2 new files u=in directory and it increase every time

here is my sourcecode

Source: stackoverflow-php

Ajax file upload, want to pass an int but i have no idea how

i want to pass on an int (The project id) to make a query in the php file that uploads the file, everything works, but i have to pass on the int which is $project[0][0]; towards the file_upload_parse.php. someone please help me out

this is currently the code (HTML/ PHP):

    if ($project[0][5] == true) {
        echo "
" . $project[0][2] . " " . $lang['VIEW_PREVIOUS'] . "
<h1><i class="File Pdf Outline icon" style="font-size: 2em; padding:14px; margin-right: 20px;"></i>" . $project[0][1] . " " . $lang['PRESENTATION'] . " </h1> </div> <br> </div> <form style='margin-bottom:0px;' id='upload_form' method='POST' enctype='multipart/form-data'>
" . $lang['DOWNLOAD'] . "
</div> </div> </form> </div> </div>"; } ?> </div>

this is currently the code (THE JS IS LOCATED ON THE BOTTOM OF THE PAGE) (JS/PHP):

function selectFile() {
    var file = _("presentation").files[0];

function uploadFile(file) {
    var file = _("presentation").files[0];

    var formdata = new FormData();
    formdata.append("presentation", file);
    var ajax = new XMLHttpRequest();
    ajax.upload.addEventListener("progress", progressHandler, false);
    ajax.addEventListener("load", completeHandler, false);
    ajax.addEventListener("error", errorHandler, false);
    ajax.addEventListener("abort", abortHandler, false);"POST", "templates/upload/file_upload_parse.php");


function progressHandler(event) {
    var percent = (event.loaded / * 100;
    // _("progressBar").value = percent = Math.round(percent);
    // _("status").innerHTML = Math.round(percent)+ " uploaded";
function completeHandler(event) {
function errorHandler(event) {
    _("status").innerHTML = "failed";
function abortHandler(event) {
    _("progressBar").value = 0;

this is currently the code (HTML/ PHP):

include "../../models/login.php";
$con = new User();

if (isset($_FILES['presentation'])){
$filename = $_FILES['presentation']['name'];
$fileTmpLoc = $_FILES['presentation']['tmp_name'];
$fileType = $_FILES['presentation']['type'];
$fileSize = $_FILES['presentation']['size'];
$fileErrorMsg = $_FILES['presentation']['error'];

$file_ext = explode('.',$filename);
$file_ext = strtolower(end($file_ext));

$allowed =  array('txt' , 'pdf','png','jpg');
if (in_array($file_ext, $allowed)){
    if ($fileSize <= 2000000000){
        $file_name_new = uniqid('', true) . '.' . $file_ext;
        if (move_uploaded_file($fileTmpLoc, "../../uploads/$file_name_new")){
//            $con->executeQuery("");



Source: stackoverflow-php