简体   繁体   English

jQuery Ajax不会出错

[英]JQuery Ajax won't error

function moveIt(result, finish) {
    $result = $(result);
    $result.find('#main-content-wrapper').appendTo('#aem-content');
    $result.appendTo('#scriptDiv');

    if (finish !== undefined) {
        finish();
    }
}

function isAuthSpace(path) {
    if (path.toLowerCase().indexOf("shop/") > 0) return true;
    return false;
}

function finishInjecting() {
    ProcessInjection("div.dyna-prd-lnk", parseDivTag,   pumpDivTag, "Shop.aspx/GetLinks");
}

function AEMLoadError(isAuth) {
    var fileToLoad = "unAuth.html";
    if (isAuth) {
        fileToLoad = "auth.html";
    }
    $("#aem-content").load(fileToLoad, finishInjecting);
}

function breakAEMLoadPath(path) {
    return BreakTheAEMLoadPath === true ? "2" : path;
}

function PullAEM(path, finish) {
    var isAuth = isAuthSpace(path);
    var ppath = breakAEMLoadPath(path);
    $.ajax({
        url: ppath,
        success: function (result) {
            moveIt(result, finish);
        },
        error: function () {
            AEMLoadError(isAuth);
        },
        dataType: "html"
    });
}

When I call the above function PullAEM(path, finish), no matter what value I put in path parameter, the ajax call calls the success function, if the path has garbage in it, say it's empty, the call succeeds (even though it should fail). 当我调用上面的函数PullAEM(path,finish)时,无论我在path参数中输入什么值,ajax调用都会调用成功函数,如果该路径中包含垃圾,说明它为空,则调用成功(即使它应该会失败)。 When it should fail, the result contains the contents of the current page which is not what path is pointing to. 当它应该失败时,结果将包含当前页面的内容,而不是路径所指向的内容。 Anyone have any idea what I'm doing wrong? 有人知道我在做什么错吗?

Thanks for everyone answering so fast. 感谢大家这么快回答。 I'm not sure what the problem was but after I cleaned it all up to post it up here it worked great! 我不确定问题出在哪里,但是在我将所有问题整理干净后发布到这里,效果很好! Though, it ay have been something you both were saying. 虽然,你们俩都一直在说这句话。

This is working perfectly.... 这工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM