duandaotui5633 2017-02-09 06:20
浏览 107

如何在没有页面刷新的情况下ajax发布URL参数更改

Depending on the change in URL parameter my values in the html changes. So basically i am passing these values to a json file. Since the page is refreshing because of the post my values are getting erased.I tried event prevent default, but its not working for me.

var carryOver ={"Jan":"","Feb":""};
var parameters = getParameterByName('month')//gets the current URL parameter
if(parameters == '01-2017'){
    $('#monthQuota').html(janQuota);
    carryOver["Jan"] = 300;
}
else if(parameters == '02-2017'){
    carryOver["Feb"] = 400;
}
$(function() {
  $('parameters').on('change', function (e) {
    e.preventDefault();
    $.ajax({
        type: "POST",
        url: "utilization-2017-test.php",
        data: {
           json: JSON.stringify(monthBalances)
        }
      })
    })
 })
  • 写回答

1条回答 默认 最新

  • dousa1630 2017-02-09 06:35
    关注

    sir, javascript or jquery can detect the #(hash)change but not the parameter change.If you clicked on a link and #tag changed then the script or event will detect that and page will not get reloaded but to change parameters you are going for an entry in the browser Url, so your values getting refreshed.

    So please do one thing that keeps a text box and enter values in that then you get the value from textbox and go for service call instead of taking input from URL

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器