Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
39
rated 0 times [  42] [ 3]  / answers: 1 / hits: 46488  / 11 Years ago, tue, may 28, 2013, 12:00:00

I wanted to get a img src to php variable when a user clicks it so i used jquery function to get img src when user clicks that image.Below jquery is for fetching img src



$(img).click(function() {
var ipath = $(this).attr('src');
})


now i tried something like this to get the ipath value to php variable



$.ajax({ type:'POST', url: 'sample.php',
dataType: 'HTML', data: dataString,
success: function(data)
{
}
});
});


I'm not sure about using Ajax correctly can anyone help with Ajax function to get this done?
Thank you.


More From » php

 Answers
2

You should make ajax call when img is clicked for example:



$(function (){
$(#myimg).click(function() {
$.ajax({
type: POST,
url: some.php,
data: { param: $(this).attr('src'); }
}).done(function( msg ) {
alert( Data Saved: + msg );
});
});
}


html code



<img src=http://yourimage.jpg alt=image id=myimg />


in some.php use



 echo $_POST['param'];


to get value and if you used type:GET you should use then $_GET to obtain value.


[#77984] Sunday, May 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayla

Total Points: 681
Total Questions: 102
Total Answers: 108

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
tayla questions
Fri, Mar 5, 21, 00:00, 3 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
;