Home how to use this ajax , why function is not define?
Reply: 1

how to use this ajax , why function is not define?

user3155787
1#
user3155787 Published in 2018-01-13 01:34:49Z

i am beginner for javascript, this is old code i am beginner for javascript, this is old code

i am beginner for javascript, this is old code

===============

<!doctype html>
<head>
    <meta charset="utf-8"/>
</head>
<body>
<div>可打开浏览器控制台查看结果</div>
<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="./md5.js"></script>
<script type="text/javascript">
var appid = '2015063000000001';
var key = '12345678';
var salt = (new Date).getTime();
var query = 'apple';
// 多个query可以用\n连接  如 query='apple\norange\nbanana\npear'
var from = 'en';
var to = 'zh';
var str1 = appid + query + salt +key;
var sign = MD5(str1);
$.ajax({
    url: 'http://api.fanyi.baidu.com/api/trans/vip/translate',
    type: 'get',
    dataType: 'jsonp',
    data: {
        q: query,`
        appid: appid,
        salt: salt,
        from: from,
        to: to,
        sign: sign
    },
    success: function (data) {
        console.log(data);
    } 
});

</script>
</body>

===================

i want to use it in my js. like this :

var appid = '2015063000000001';
var key   = '123445676';
var salt  = (new Date).getTime();
var query = 'apple';

var from = 'en';
var to = 'zh';
var str1 = appid + query + salt +key;
var sign = MD5(str1);

// get_baidu();

function get_baidu()
{



    console.log('get baidu run');

    $.ajax({
        // url: 'http://api.fanyi.baidu.com/api/trans/vip/translate',
        // type: 'get',
        // dataType: 'jsonp',
        // data: {
        //     q: query,
        //     appid: appid,
        //     salt: salt,
        //     from: from,
        //     to: to,
        //     sign: sign
        // },
        // success: function (data) {
        //     console.log(data);
        // } 
    }); 



}

=========================

but my code is not work , err

baiduTranslate.js:32 Uncaught ReferenceError: ajax is not defined
    at get_baidu (baiduTranslate.js:32)
    at xhrCallback (doubleTedder.js:93)
    at XMLHttpRequest.xhr.onreadystatechange (doubleTedder.js:76)

why ? how do i should to make it work ?

Christian Ahidjo
2#
Christian Ahidjo Reply to 2018-01-13 01:42:58Z

try to move <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script> inside the <head></head> tag. And try jQuery.ajax({... instead of $.ajax({...

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.382 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO