0

I am coding a php album to preview the images and comments i am using Jquery below is code

php

$photo .="<div class=\"imagearray\"><span>".$imagerealname ."</span><br/><div class=\"imagecontent\"><image src='uploads/thumb_".$query['imagesrc']."' alt='image' id='".$query['ImageSN']."' /></div>share delete</div>";

To call images from Database

then click on any image jquery function executes

// display photo preview ajaxy
    $('.imagearray .imagecontent img').click(function (event) {
        if (event.preventDefault) event.preventDefault();

        getPhotoPreviewAjx($(this).attr('id'));
    });
})

getPhotoPreviewAjx is

function getPhotoPreviewAjx(id) {

        var id = id;
        alert(id);  
    $.post('commentblock.php',
            { action: 'get_info', Id: id },
        function(data){
            $('#photo_preview .pleft').html(data.data1);
            $('#photo_preview .pright').html(data.data2);
            $('#photo_preview').show();
        }, "json"
    );
};

this code is working till alert(id); and next i dont think it is passing values to commentblock.php

starting of commentblock.php is

if( $_POST['action'] == "get_info" &&  isset($_POST['Id']))
{
echo $_POST['id'];

and it is not working need some guideness struck here :(

6
  • Could you add another alert in postback call? function(data){ console.info(data); .... Commented Mar 21, 2014 at 15:17
  • What is var id = id; supposed to do? Commented Mar 21, 2014 at 15:23
  • i tried that tell me something will this show in console if yes than nothing in console Commented Mar 21, 2014 at 15:24
  • @RocketHazmat I was debugging to check jquery passing id or not Commented Mar 21, 2014 at 15:25
  • Your AJAX call is just echoing the id. So, data.data1 won't exist. Commented Mar 21, 2014 at 15:25

2 Answers 2

1

(After debugging)

The javascript works correctly. There is an error or something stopping it working correctly in server side code.

Sign up to request clarification or add additional context in comments.

7 Comments

Nothing no result id and action are empty any other way through jquery to make that call?
Add console.log($(this).attr('id')); before getPhotoPreviewAjx($(this).attr('id')); and tell me what it outputs to the developer console.
Can you see the POST data sent by the AJAX request in the network section of your web browsers developer tools?
in developer tools i can only see 2 which is img id and problem is in function getPhotoPreviewAjx i appreciate your help
I can see "action:get_info, Id:2" being posted from the ajax request.
|
0

try changing { action: 'get_info', Id: id }, to { data: $("form").serialize() } (I'm assuming your data is coming from inputs in a form element named 'get_info' and 'Id')

1 Comment

no form here like i pasted in my Question id is coming from Img click function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.