user3902519 February 2016

Write non form data to xml using php

I am coding a video platform. When anyone sees the video and hit the like button the like should be incremented by one and should be written to xml file - I want to do this with php. And when the like symbol is clicked, the php should not be loaded but it should be executed.

Here is my code:

HTML:

<a href='#' onclick='doLike(id)'><i class='material-icons'        style='float:bottom'>thumb_up</i></a>

JavaScript:

function doLike(id){
$.ajax({
    type: "POST",
    async: true,
    url: "likup.php",
    cache: false,
    contentType: false,
    processData: false,
    error: function(){alert('Cannot reach file');},
    success:
            function(){
                alert("Saved Successfully");
            }
});}

PHP:

error_reporting(E_ALL);
$file = 'xml/shortfilm/filmname.xml';
$xml = simplexml_load_file($file);
$xml->Shortfilm[0]->like= 2;

But I am still unable to achieve what I want.

Answers


Lajos Arpad February 2016

onclick='doLike(id)'

On click doList(id) will be called. What is id? Is it defined? You need to make sure that this parameter has the correct value. Your doLike does not send the id to the server. You need to send it, otherwise your server will not receive it. Your server, in turn should process the request and save the like into the xml.

Post Status

Asked in February 2016
Viewed 1,748 times
Voted 4
Answered 1 times

Search




Leave an answer