代码日志记录在$.get请求中运行时未定义,但在页面上运行时工作正常

Code logging undefined when ran in a $.get request, but when ran on the page it works fine?

本文关键字:运行时 工作 未定义 日志 get 请求 代码 记录      更新时间:2023-09-26

我的代码在运行时未定义日志,但在当前页面上运行时(删除$.get请求和$(f)

这是我的代码:

var product = 20219291;
function check(id) {
    $.get('http://m.roblox.com/items/'+id+'/privatesales').success(function(r) {
        var d = r.replace(/img/gi,"flip");
        var f = $(d).find(".ui-btn-text a").first().attr('href');
        console.log(f);
        var s = link.substring(0, link.indexOf('&expectedPrice'));
        var userAssetId = s.replace('/Catalog/VerifyTransfer?userAssetOptionId=', '')
        var price = link.substring(link.indexOf("&expectedPrice=") + "&expectedPrice=".length);
        console.log(userAssetId, price);
    });
}
check(161211433);

当您通过浏览器访问此页面时,您已登录,因此存在活动会话。

当您尝试使用ajax访问该页面时,我想返回的html就是该页面的内容:https://m.roblox.com/Login?ReturnUrl=%2fitems%2f161211433%2fprivatesales

如果你需要登录才能访问一些内容,我建议你使用服务器端的api:

http://wiki.roblox.com/index.php?title=User-created_web_API的