dongzhuo1930 2011-10-20 10:16
浏览 329

如何使用Ajax在div中添加页面内容?

I have a list in my site, and when I click each of the list items, I want the div next to them to reload with ajax, so as not to reload the whole page.

Here is my javascript

  parameters = "category_id="+categoryId;
  var result = ajaxFunction("changeCategory.php", parameters);
  $("#mydiv").html(result);

The ajaxFunction() function is the regular $.ajax() jQuery function, with "POST". In the "changeCategory.php" I call with include another php file. The problem is that the whole page is reloaded instead of only the div. I want to use this ajax function I have, cause I want to send data to my php file.

Does anyone know what should I do to reload only the div?

Thanks in advance

  • 写回答

5条回答 默认 最新

  • douyan1882 2011-10-20 10:22
    关注

    Try using load to load the div with the url contents -

    $("#mydiv").load("changeCategory.php", {category_id: "category_id_value"} );
    

    You can pass data to the url.

    The POST method is used if data is provided as an object; otherwise, GET is assumed.

    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64