Asked  7 Months ago    Answers:  5   Viewed   46 times

I have a div which contains some text for the database:

<div id="summary">Here is summary of movie</div>

And list of links:

<a href="?id=1" class="movie">Name of movie</a>
<a href="?id=2" class="movie">Name of movie</a>

The process should be something like this:

  1. Click on the link
  2. Ajax using the url of the link to pass data via GET to php file / same page
  3. PHP returns string
  4. The div is changed to this string



function getSummary(id)

     type: "GET",
     url: 'Your URL',
     data: "id=" + id, // appears as $_GET['id'] @ your backend side
     success: function(data) {
           // data is ur summary



And add onclick event in your lists

<a onclick="getSummary('1')">View Text</a>
<div id="#summary">This text will be replaced when the onclick event (link is clicked) is triggered.</div>
Wednesday, March 31, 2021
answered 7 Months ago

Take a look at this jsFiddle I put together - it may help.

I'm making an AJAX call (a POST in this case since it's just HTML and that's what jsFiddle supports for HTML requests - but it would be no different for a $.get for you) that gets data and appends it to a table data cell (<td>). The whole page doesn't update - just the section that I'm targeting -- in this case, the <td> cell, which keeps having "hello's" appended into it.

I hope this helps. Let me know if you have add'l questions.

Wednesday, March 31, 2021
answered 7 Months ago

To achieve this you can either do a synchronous ajax call like described in this answer, but that's something which is incredibly dangerous for the performance of your website.

Alternatively - and this is the right way - you should have an external variable whether the username is available, as soon as the user inputs something you do the request and if it's valid you change the variable otherwise you show an warning message. Next in your validateRegistration() function you only check the external variable (+ possible some form of callback, depending on where you call it from). The advantage being that the user can still continue doing things (like filling out the rest of the form) whilst the request is pending.

Saturday, May 29, 2021
answered 5 Months ago

Most likely, your server limits the number of concurrent connections per user to 1. Or, you are using sessions and the first script has it locked. The second script will be blocked until the first one releases its lock on the session file. Only use session_start() if you need to, and release the lock with session_write_close() as soon as you are done with it.

Edit: I'm not sure if this will work, but you could try it. Each time you want to update the session, call session_start(), update the session, then call session_write_close(). I'm not sure if you are allowed to do that multiple times in a script, but it seems like it should work.

Saturday, May 29, 2021
answered 5 Months ago

Try utilizing json to upload , process file object


<div id="drop" class="drop-area ui-widget-header">
  <div class="drop-area-label">Drop image here</div>
<br />
<form id="upload">
  <input type="file" name="file" id="file" multiple="true" accepts="image/*" />
  <ul class="gallery-image-list" id="uploads">
    <!-- The file uploads will be shown here -->
<div id="listTable"></div>


  #uploads {

  #uploads li {

  #drop {
      width: 90%;
      height: 100px;
      padding: 0.5em;
      float: left;
      margin: 10px;
      border: 8px dotted grey;

  #drop.hover {
      border: 8px dotted green;

  #drop.err {
      border: 8px dotted orangered;


var display = $("#uploads"); // cache `#uploads`, `this` at `$.ajax()`
var droppable = $("#drop")[0]; // cache `#drop` selector
    context: display,
    contentType: "application/json",
    dataType: "json",
    beforeSend: function (jqxhr, settings) {
        // pre-process `file`
        var file = JSON.parse(
        // add `progress` element for each `file`
        var progress = $("<progress />", {
                "class": "file-" + (!!$("progress").length 
                         ? $("progress").length 
                         : "0"),
                "min": 0,
                "max": 0,
                "value": 0,
        this.append(progress, + "<br />"); = progress.attr("class"); 

var processFiles = function processFiles(event) {
    // process `input[type=file]`, `droppable` `file`
    var files = || event.dataTransfer.files;
    var images = $.map(files, function (file, i) {
        var reader = new FileReader();
        var dfd = new $.Deferred();
        reader.onload = function (e) {
            dfd.resolveWith(file, [])
        reader.readAsDataURL(new Blob([file], {
            "type": file.type
        return dfd.then(function (data) {
            return $.ajax({
                type: "POST",
                url: "/echo/json/",
                data: {
                    "file": JSON.stringify({
                            "file": data,
                            "size": this.size,
                            "type": this.type
                xhr: function () {
                    // do `progress` event stuff
                    var uploads = this.context;
                    var progress = this.context.find("progress:last");
                    var xhrUpload = $.ajaxSettings.xhr();
                    if (xhrUpload.upload) {
                        xhrUpload.upload.onprogress = function (evt) {
                                    "value": evt.loaded
                        xhrUpload.upload.onloadend = function (evt) {
                            var progressData = progress.eq(-1);
                                    + " upload complete...");
                            var img = new Image;
                            img.onload = function () {
                                if (this.complete) {
                                      + " preview loading..."

                        uploads.append("<br /><li>", img, "</li><br />");
                    return xhrUpload;
            .then(function (data, textStatus, jqxhr) {
                this.find("img[class=" + + "]")
                .attr("src", data.file)
                .before("<span>" + + "</span><br />");
                return data
            }, function (jqxhr, textStatus, errorThrown) {
                return errorThrown
    $.when.apply(display, images).then(function () {
        var result = $.makeArray(arguments);
        console.log(result.length, "uploads complete");
    }, function err(jqxhr, textStatus, errorThrown) {
        console.log(jqxhr, textStatus, errorThrown)

.on("change", "input[name^=file]", processFiles);
// process `droppable` events
droppable.ondragover = function () {
    return false;

droppable.ondragend = function () {
    return false;

droppable.ondrop = function (e) {
    var image =
        .every(function (img, i) {
        return /^image/.test(img.type)
    // if `file`, file type `image` , process `file`
    if (!!e.dataTransfer.files.length && image) {
            .css("color", "blue")
            .html(function (i, html) {
            $(this).delay(3000, "msg").queue("msg", function () {
                $(this).css("color", "initial").html(html)
            return "File dropped, processing file upload...";
    } else {
            // if dropped `file` _not_ `image`
            .css("color", "darkred")
            .html(function (i, html) {
            $(this).delay(3000, "msg").queue("msg", function () {
                $(this).css("color", "initial").html(html)
            return "Please drop image file...";


  if (isset($_POST["file"])) {
    // do php stuff
    // call `json_encode` on `file` object
    $file = json_encode($_POST["file"]);
    // return `file` as `json` string
    echo $file;


Tuesday, June 1, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :