dousha1831 2012-04-04 12:22
浏览 98

如何使用Ajax调用特定的PHP函数和JQuery的结果

My first contact with Ajax is happening right now, and I'm kind a confused. I've read many of questions asked, but I'm not able to read the answer, that is most likely here somewhere.

Situation is, I'm using OOP PHP approach, and all I do go through index.php with parameters. So I do not call any other .php file in form posts, button clicks..

I've created an HTML listbox (which I'd like to remove vertical scrollbar, but that's just a bonus to resolve), which feeds my categories in it.

Now, by clicking each category I'd like to call certain function that would then generate output for the other div.

function swapContent(){
$("#myPresentDiv").html('<img src="../../imgs/ajax-loader-big.gif"/>').show();
var cat = $('#listbox').val();
$("#action").change(alert(cat));
var url = "&s=".cat;
$.post(url, {contentVar: cat} ,function(data) {
   $("#myPresentDiv").html(data).show();
});  

}

So, my JQuery script picks up correct Category, I alert it to alert dialog, so I'm sure that's fine, and then with code as it is at the moment, I reload my whole page so I get, page in page in page in page...

I'm trying to figure out how to write JQ ajax call, that would return only the results, not the whole page.

can I put URL "index.php&s="cat, and then somehow tell to ajax "go through index, call function displayresults ($cat); ?

Hope everything I wrote make sense to you :)

Tnx.

  • 写回答

6条回答 默认 最新

  • dongshou9878 2012-04-04 12:26
    关注

    If you look at the frameworks or cms out there, they basically have routes that map calls to your index.php function to methods of the controller.

    This is a complex argument, you could try to start out reading this article

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题