douhe6181 2012-03-27 19:42
浏览 56
已采纳

使用jquery刷新div中的信息

I have researched and researched and I am trying to use jquery to refresh the information inside a div but so far to no avail..

I have a div.... its display is hidden.... I use jquery to click on an anchor tag that fades this div in, inside this div I have a pp calender for a customer to choose a date, when they choose a date they are navigated to another page however I have two drop down menus so they can change the month and year view of the calender (that was a terrifying php experience for me!). When they change the month view the 'action' of the form sends them to the same page but with the calender month view as selected.. the problem is that when the form sends us back to the calander page, the div is hidden again and we must click the unfade div anchor tag.

I can only think of the following way of doing this; when the drop down menu form is clicked instead of the page reloading with the updated calender, just reload the div (as i store the php for the calender (all of it) inside the div to try and do this).

but I can only find code to reload an a page inside the div.

Any ideas... because the question could be seen as a little generic i am not sure what code I can give to help....

lets say the div in question is called... #terms9 and the anchor tag is called #showcalender. Any code that you need please request.

Thanks for reading

  • 写回答

2条回答 默认 最新

  • donglengli0644 2012-03-27 19:59
    关注

    Let's say your action url is calendar.php.

    When you change your drop down menu, you want the handler to make a request for the same page and then load the calendar div from that request into the current calendar div:

    $('#mydropdown').on('change', function() {
          $.get('calendar.php', { month: $(this).val() }, function(data) {
               $('#mycalendar').replaceWith( $(data).filter('#mycalendar') );
          });
    });
    

    .get() is a shorthand method that requests the url, with the parameters ({ month: ... }), and calls the provided callback function with the returned data. Here, I parse that data for the correct selector and replace the existing one.

    I clearly make a lot of assumptions about your code here, but this is the basic idea. You could also use .load() or any of the other ajax functions depending on your needs.

    Here is a (slightly convoluted) example using .post():

    http://jsfiddle.net/SHwtr/1/

    In this case, /echo/html/ would be your php url, and instead of html: ..., you would put your php parameters.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛