weixin_33743880 2015-10-22 13:28 采纳率: 0%
浏览 19

当Ajax工作但不工作时

I have been scouring the internet for a solution. I don't really think this is language specific, but I'm in ColdFusion using JQuery to Ajax out to a cute little dialog. This code works on many computers, different servers, IIS and Apache...but for me, no. the Ajax calls work perfectly fine but in the code, if something fails in the call, I'm supposed to just see an "OK" script box popup. And for all these calls, that the only things I see...but when I dig into the actual call and look at what ajax is sending and receiving everything is correct...well one thing that is NOT is there for some reason on MY computer, the return has some preceeding whitespace in the JSON data...no one else has that problem...but we are all running the same code. Almost all of my research points to things I could do wrong that would be causing ajax to fail...but that is NOT technically the problem...Ajax works just fine and even returns 99% of exactly what I expect it to. I have to believe there is something environmentally different or something "outside" (at least of the code) is impacting the results so they are treated as invalid...but again, same code works perfectly in many "elsewheres". Here is the gist of this pretty simple code:

$(document).ready(function() {
    $('##viewaction').on('shown.bs.modal', function (e) {
        $('##records-table').empty();
        var linkSource = $(e.relatedTarget);// link that triggered modal
        var actionId = linkSource.data('action-id');
        var actionName = linkSource.data('action');
        $.ajax({
            type: "GET",
            dataType: 'json',
            cache: false,
            url: 'portal/plugins/test/AjaxProxy.cfc',
            data: { method: "ViewActionRecord", actionId: actionId }
        })
        .done(function( results ) {
            response = eval(results);
            $('##action-name').text(actionName);
            $.each(response.DATA, function(i, item) {
                // undefined is less likely but object will appear if the value in our struct converted to json is a blank
                // this ultimately only works if the struct we are delivering is flat...otherwise, objects could be valid
                // values here...warning for future "nested" views of data
                if(typeof item =="undefined" || typeof item == "object") {
                    $('<tr>').html("<td>" + i + "</td><td>&nbsp;</td>").appendTo('##records-table');
                } else {
                    $('<tr>').html("<td>" + i + "</td><td>" + item + "</td>").appendTo('##records-table');
                };
            });
        })
        .fail(function(e) {
            //alert(e.responseText);
            alert(e.statusText);
        });
    });
});

and in my environment...no matter how right the data might appear, I'll always hit the .fail() segment.

Now its important to note that ALL ajax fails for me...not just this code. Old code working for the last 3-4 years is exhibiting the same kind of response anomaly.

And it gets worse...this just started happening. With no significant installs or updates for Window 8.1 and IIS of which I am aware nor any significant installed software recently..ALL my ajax calls have simply stopped working and I can find nothing that points to the culprit.

And if you thought it were not possible...one more thing has happened that makes me think I'm never going to be rid of this and I should pack up and start flipping burgers...I had one of our sys-admins setup a remote desktop environment for me...HE set up all the baseline and I just copied code from our repository and installed a few tools (same tools other developers use) and initially everything works fine...then one day, literally out of the blue (I know, I know how many times have you heard this), it stops working.

I'm willing to search for anything, uninstall some things and reinstall (blowing away completely is not a good option because of the remote desktop test above), install some things...but for the life of me I cannot figure out what has happened that would create such a bizarre circumstances that cannot be replicated by others using the same code and very similar environments.

I'm not holding my breath...but I had to put something out here if for no other reason than due diligence.

-- More Information --

What exactly does it return?

Exactly the JSON I would expect, every time, except with a CR+LF in front of it...now idea why since the same code on other boxes does NOT produce that extra whitespace

Are you all using the same browser? Do you have a specific error thrown at you?

Every browser, current version (IE, FIREFOX, CHROME and yes, even Safari) and as part of the problem, there is no error thrown. Ajax, as in my sample code, is hitting the .fail() segment of code BUT there is no error in the data

what browser you using??and are there any errors in console?

Browsers answered above and no, no errors in the console, just a solid gold successful GET result with data in it

Are you using the latest released jQuery? If not, I would try a newer or the latest version.

Went back and forth a version (not currently distributed most recent), but again, this exact code works everywhere else WITH it's bundled verison of JQuery...and with no error responses, as far as JQuery is concerned, it's happy.

Is the "suppress white space" cfadmin setting turned on in other environments, but not your local one?

Absolutely disabled and even stretched the imagination and went into the CF code and make sure the methods that create the data all have output set properly (component AND method) and all JSON prefixing in CF admin is disabled. Also have check all related CF admin settings with other servers that work and they are all the same...plus...lacks the explanation of why was it JUST working on this box and suddenly fail when none of those settings changed.

And that is CF 10 and CF 11.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题
    • ¥15 目标检测项目无法读取视频
    • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
    • ¥100 求采集电商背景音乐的方法
    • ¥15 数学建模竞赛求指导帮助