普通网友 2015-02-20 18:06
浏览 13

使用JQuery更新表

I am using jQuery to create a table of prices and dates. After some trials and tribulations this is now working well. To further improve it, I want to offer site visitors the possibility of displaying the prices in other currencies. So I need to update the table with most of the data the same, changing only the currency.

The table is initially loaded with this code

function Dates(getresult){
         $.ajax ({
            type: 'post',
            url: '/includes/calendar_price_currency.php',
            data: $("#StartDateCal").serialize(),
            success: function(result) {
             $("#pricePickerResult").html(result);
            }
        });
    }

// Auto load ajax
Dates('getresult');

This takes hidden inputs in the StartDateCal div (including the name of the currency) and runs it through the calendar_price_currency.php file. The result is displayed in the pricePickerResult div.

Just below that div I have added buttons to change the currency. At the moment I have this code to update the table

// Euro currency Link load ajax
$('a#euro').click(function () {
         $.ajax ({
            type: 'post',
            url: '/includes/calendar_price_currency.php',
            data: $("#StartDateCal").serialize(),
            data: {'currency': 'EUR'},
            success: function(result) {
             $("#pricePickerResult").html(result);
            }
        });
    return false;
});

but it doesn't work! Clicking the link reloads the table, but with no content. I presume I am doing something wrong with the "data" lines, but I don't know what. I've tried removing the second line and then nothing visibly happens but I assume the table is reloading with the same data, so there is nothing to see.

Effectively I need most of the data to remain the same and just the currency to change. I had hoped that my second data line would just overwrite the currency element, but it looks like it overwrites everything. Is there a way of mixing "serialize" with another way of loading data?

EDIT

I found a bit of extra info here, and then changed my script to this:

$('a#euro').click(function () {
    var data = $('#StartDateCal').serializeArray();
    data.push({name: 'currency', value: 'EUR'});
    $.ajax ({
            type: 'post',
            url: '/includes/calendar_price_currency.php',
            data: data,
            success: function(result) {
            $("#pricePickerResult").html(result);
            }
        });
    return false;


   });
  • 写回答

2条回答 默认 最新

  • weixin_33691598 2015-02-20 18:46
    关注

    You have two data values that you're sending

    data: $("#StartDateCal").serialize(),
    data: {'currency': 'EUR'},
    

    Remove one.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀