如何使用jquery“加载”?传递变量时加载页面片段的方法?

发布于 2024-10-07 16:51:24 字数 243 浏览 0 评论 0原文

不确定是否有人问过这个问题,但给出以下代码,就这样了...

$('#infoPane').load('showInfo.php #info');

如何将变量传递到页面但仅加载页面片段?

$('#imgPane').load('showInfo.php?q='+$q+ '#picture');

上面的代码不起作用,所以任何帮助将不胜感激

Not sure if this has been asked, but here it goes, given the following code...

$('#infoPane').load('showInfo.php #info');

How do a pass variable to the page yet only just load the page fragment?

$('#imgPane').load('showInfo.php?q='+$q+ '#picture');

The above code does not work so any help would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坐在坟头思考人生 2024-10-14 16:51:24

它可能不起作用,因为间距不正确:

$('#imgPane').load('showInfo.php?q='+$q+' #picture');

在您的示例中,您尝试加载: showInfo.php?q=whatever#picture 而不是 showInfo.php?q=不管 #picture

但是,您应该能够将数据发布到您的脚本,类似于以下内容:

$('#imgPane').load('showInfo.php #picture', { 'q' : $q });

传递数据是 jQuery .load() 参数。

It probably doesn't work because the spacing is incorrect:

$('#imgPane').load('showInfo.php?q='+$q+' #picture');

In your example, you're trying to load: showInfo.php?q=whatever#picture rather than showInfo.php?q=whatever #picture

However, you should be able to post data to your script similar to the following:

$('#imgPane').load('showInfo.php #picture', { 'q' : $q });

Passing data is one of the jQuery .load() parameters.

櫻之舞 2024-10-14 16:51:24

我不知道 jQuery 在这里是如何工作的,确切地说,但是使用 URL 哈希作为 ID 似乎很奇怪。它大概应该是这样的:

$('#imgPane').load('showInfo.php?q='+$q+' #picture');

I do not know how jQuery works here, exactly, but using the URL hash as ID seems odd. It should probably look like this:

$('#imgPane').load('showInfo.php?q='+$q+' #picture');
那伤。 2024-10-14 16:51:24

生成的 URL 不遵循“神奇”语法:#,但显示为 showInfo.php?q=#picture(无空格) 。尝试:

$('#imgPane').load('showInfo.php?q='+$q+' #picture');

或者,您是否尝试通过第二个参数(data)传递值?

$('#imgPane').load('showInfo.php #picture', {q: $q});

The resulting URL does not follow the "magic" syntax: <url> #<id-of-fragment-to-load>, but comes out as showInfo.php?q=<value-of-$q>#picture (no space). Try:

$('#imgPane').load('showInfo.php?q='+$q+' #picture');

Alternatively, did you try passing the value via the second argument (data)?

$('#imgPane').load('showInfo.php #picture', {q: $q});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文