简体   繁体   English

从HTML页面使用jQuery.load的参数

[英]consume parameter of jQuery.load from html page

I use the following jQuery.Load to load external html which contains js functions: 我使用以下jQuery.Load加载包含js函数的外部html:

$("#feeds").load("feeds.html", {limit: 25})

How can I consume the parameter from the html page? 如何使用html页面中的参数?

You'll need server support and some sort of templating system (where the server passes the parameter to the template, or its renderer) if you want to access it. 如果要访问它,则需要服务器支持和某种模板系统(服务器将参数传递给模板或其渲染器)。 Otherwise, you'll need to postprocess the response from the load yourself. 否则,您需要自己对加载后的响应进行后处理。

If you want to access it from your HTML file, then I suggest sending the 'limit' variable by using GET, instead of POST, which you are doing. 如果要从HTML文件访问它,则建议使用GET(而不是POST)发送“ limit”变量。

In otherwords, you can GET by doing this: 换句话说,您可以通过执行以下操作获取:

$("#feeds").load("feeds.html?limit=25")

Then you can parse 'location.search' to get your querystring value. 然后,您可以解析“ location.search”以获取您的querystring值。

If you are using ASP.NET, then it is really simply to use a bit of server-side code to do something like: 如果您使用的是ASP.NET,则实际上只是使用一些服务器端代码来执行以下操作:

<script>
    var limit = '<%=Request.Params["limit"]%>';
</script>

HTH, SR 顺时针

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM