问题描述
我想,当用户点击它,所以我用jQuery函数来获得IMG SRC当用户点击image.Below jQuery是为获取IMG SRC
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');
})
现在我想这样的事情来获得IPATH值PHP变量
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)
{
}
});
});
我不知道如何使用Ajax的正确谁能帮助使用Ajax功能,以完成这件事?谢谢你。
I'm not sure about using Ajax correctly can anyone help with Ajax function to get this done?Thank you.
推荐答案
您应该AJAX调用时,IMG被点击,例如:
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" />
在 some.php 使用
echo $_POST['param'];
获得的价值,如果你使用类型:GET
你应该用那么 $ _ GET
来获取值
to get value and if you used type:GET
you should use then $_GET
to obtain value.
这篇关于如何发送或Jquery的变量值赋值给PHP变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!