打字稿和jquery ajax [英] Typescript and jquery ajax

查看:72
本文介绍了打字稿和jquery ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下功能:

更新:已添加返回$ .ajax

Updated: added return to $.ajax

searchAjax({url = 'app/php/check.php', data}: {url: any, data: any}): any 
{   
    return $.ajax({
        url: url,
        type: 'post',
        dataType: 'text', 
        data: { data },
        success: function (return_data)
        {   
            return String(return_data);
        },  
        error: function (xhr, status, error) 
        {   
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
            return err.Message;
        }   
    }); 
}

现在,check.php返回 echo'hi 。只是为了测试,我正在尝试console.log响应(在这种情况下 return_data )。但是当我尝试console.log时,我收到错误 EXCEPTION:hi未定义

For now, check.php returns echo 'hi'. Just for testing, I'm trying to console.log the response (in this case return_data). However I get the error EXCEPTION: hi is not defined when I try to console.log it.

更新:
现在我得到一个带有一堆东西的对象和包含实际响应的responseText。

Update: Now I get an object with a bunch of stuff and responseText which contains the actual response.

推荐答案

听起来像你的eval没有得到你认为它正在获得的文本。我相信你的结果:echo'hi'正在剥离撇号,所以你实际上正在评估echo hi。这可能是ajax客户端问题。或者您的API正在剥离它。检查您的浏览器从API接收的内容。

Sounds like your eval isn't getting the text you think it's getting. I believe your result: "echo 'hi'" is stripping the apostrophe so you're actually evaluating "echo hi". This can be an ajax client issue. Or your API is stripping it. Check to see what your browser is receiving from the API.

此外,echo不在原生javascript中

Also, echo isn't in native javascript

这篇关于打字稿和jquery ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆