weixin_33727510 2014-10-15 15:38 采纳率: 0%
浏览 35

传递变量$ .ajax调用

I want to pass js variables to an $.ajax function, like:

function myCall(elm) {
    var table = $('#realtime').dataTable(); 
    var extension = $(elm).closest("tr").find('td.extension').text();
    var agent = $(elm).closest("tr").find('td.name').text();
    alert(extension);

    $.ajax("/cura/pages/realtime/test.php/",{
        type: "GET",
        data:   {action:'agentpause',pauselocation: extension,queue: 'testq',paused: 'true'}            
    });
}

Only extension is a variable, rest hard coded. Then it doesn't work. If i hard code the value for extension variable, then the $.ajax call is successful. What's going wrong with passing extension variable?

  • 写回答

1条回答 默认 最新

  • 关注

    There was a whitespace added in front of the variable value, in the table. Removing the white space in $.ajax function with trim(), like:

    (extension.trim())
    

    Now the $.ajax call is successful.

    评论

报告相同问题?