ajax调用Java不执行,jQuery的AJAX的load()Java脚本不执行?

I've read several posts about this issue but i can't solve it.

I am loading an html file into a div. The file i am loading contains a unordered list.

This list should be expanded (a menu with submenu items) and closed. Therefore i need js.

But unfortunately this script isn't loaded.

Can anyone help me?

Would be so great! Thanks a lot :)

解决方案

If I understood what you asked correctly...

you want to load via ajax into a div on your page, lets call it;

1) div id="loadStuffHere" of (abc.html)

2) the stuff to populate "loadStuffHere" comes from xyz.html

So just do this;

$("loadStuffHere").load("xyz.html");

BUT WAIT!! You dont want to have to load everything from xyz.html you just want to load a portion of xyz.html say of (xyz.html)

So just do this;

$("loadStuffHere").load("xyz.html #loadMeOnly");

BUT WAIT!! Lets say inside of div id="loadMeOnly" is an accordion so which means it has to be initialized which means u have to also include the javascripts... hmm, what to do...

You would think of doing this;

$("loadStuffHere").load("xyz.html #loadMeOnly");

$.getScript('js/xyz.js');

Well the above sucks because a) u would need to create an external js file and b) You are actually making 2 http calls, when u could do it with 1 http call if you did it by normal non-ajax way.

So... the best solution is to get 2 things with 1 call the (HTML and the js - 1 line, 1 http) here is how u do it;

$("loadStuffHere").load("xyz.html #loadMeOnly, script");

This loads the #loadMeOnly div AND all script tags, so u would have it all... happy happy :)

the trick here is commas... u could pick and choose to load whatever doms u want

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值