weixin_33690963 2012-03-12 23:12 采纳率: 0%
浏览 45

如何用jQuery ajax发布查询字符串?

我想在页面上运行一个小脚本,并且已经收集到了需要使用的jquery函数中的POST来执行此操作。但我在发送查询字符串时遇到了麻烦——哪里出错了?

$.post("inventory.php?use=" + drag_item.attr('id'));

drag_item.attr('id')是正确的做法吗?

  • 写回答

2条回答 默认 最新

  • larry*wei 2012-03-12 23:14
    关注

    You should encode the parameters:

    $.post("inventory.php", { use: drag_item.attr('id') });
    

    Also in this example you are only sending an AJAX request but never subscribing to any success callback in order to process the results returned by the server. You could do this like that:

    $.post("inventory.php", { use: drag_item.attr('id') }, function(result) {
        // this will be executed when the AJAX call succeeds and the result
        // variable will contain the response from the inventory.php script execution
    });
    

    Also make sure that the drag_item that you are using in this example has been properly initialized to some existing DOM element and that this DOM element has an id attribute.

    Finally use a javascript debugging tool such as FireBug in FireFox or Chrome developer toolbar in Google Chrome to debug your AJAX requests and see the requests and responses being sent to and from the server and any possible errors that might occur in between.

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏