使用.load()将多个变量传递给URL [英] Passing Multiple Variables to URL using .load()

查看:62
本文介绍了使用.load()将多个变量传递给URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery中的以下语句将多个变量发送到PHP:

I'm trying to send multiple variables to PHP using the following statement in jQuery:

jQuery:

$(document).ready(function () {
    $('.modalsend').click(function () {
        $('span.user-topicid').load('get_number_comments.php?topicid=' + $(this).data('topicid') + '&page=' + '<?=$_GET['page']?>');
    });
});

如果我像这样在PHP文件中传递单个变量,则效果很好:

It works fine if I pass a single variable in the PHP file like so:

jQuery:

$('span.user-topicid').load('get_number_comments.php?topicid=' + $(this).data('topicid'))

但是,当我尝试传递& page =时,它无法将任何内容传递给具有以下变量来获取URL的PHP​​文件:

However, when I try to pass &page=, it fails to pass anything to the PHP file which has the following variables to get the URL:

PHP(get_number_comments.php):

PHP (get_number_comments.php):

$numberid = mysql_real_escape_string($_GET['topicid']);
$page = mysql_real_escape_string($_GET['page']);

我认为这可能是jQuery中带有& page =附加标记的问题,但不确定是什么原因引起的.请注意,页面位于具有第一个jQuery函数的页面的URL中.

I think it's probably an issue with the markup in the jQuery with the additional &page= but not sure what could be causing it. Note that page is in the URL of the page with the first jQuery function.

注意:问题已解决,最好先获取URL($ page = mysql_real_escape_string($ _ GET ['page']);),然后将$ page变量发送到data属性中,就像topicid一样-请参考到变量值不是传入Bootstrap Modal中的mySQL语句以获取有关该解决方案的更多详细信息

NOTE: Issue has been resolved, it is best to get the URL first ($page = mysql_real_escape_string($_GET['page']);) and send the $page variable in a data attribute just like topicid - please refer to Variable value not passing into mySQL statement in Bootstrap Modal for further details on the solution

推荐答案

我相信Amin已经回答了您的问题,但我只是想根据

I believe Amin has already answered your question but I just wanted to add that according to the .load() documentation, you can pass your data as the second argument and it should handle the encoding. So you could do something like this:

var pageVal= <?=$_GET['page']?>;
var data = { "topicid": $(this).data('topicid'), "page": pageVal };
$('span.user-topicid').load('get_number_comments.php', data);

这篇关于使用.load()将多个变量传递给URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆