如何通过AJAX将jQuery变量传递给PHP页面 [英] How to pass jQuery variable with AJAX to PHP page
本文介绍了如何通过AJAX将jQuery变量传递给PHP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用jQuery/ajax将变量"flickrurl"传递到PHP页面.它在使用纯文本字符串而不是变量时有效.我是否正确分配了变量? 在此处查看运行中的完整代码:
Trying to pass the variable "flickrurl" to a PHP page with jQuery/ajax. It works when using a plain text string and not the variable. Am I assigning the variable properly? See the full code in action here:
$trash.droppable({
accept: '#gallery > li',
activeClass: 'ui-state-highlight',
drop: function(ev, ui) {
deleteImage(ui.draggable);
//set variable equal to src of image tag in #gallery > li
var $flickrurl = $item.find('img').attr("src");
//pass variable to php page
$.post("updateDB.php", $flickrurl );
}
});
推荐答案
jQuery的AJAX函数期望JSON形式的数据.试试:
jQuery's AJAX functions expect data in JSON form. Try:
$.post("updateDB.php", { 'flickrurl': $flickrurl } );
这篇关于如何通过AJAX将jQuery变量传递给PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文