提问者:小点点

如何在jQuery$.ajax请求中获取请求url


我正在使用get函数进行扩展,但我无法从web上获取数据并将其发布到其他web上,我无法从js文件发送数据到html,有谁能帮助我如何使这个东西工作。

var q = $('.content .qtext').text();
$('[id^=question-]').append('<a class="stark" style="background:red;color: #fff;padding: 15px;cursor:pointer;">Share answer!</a>');
$('.stark').on('click', function () {
    var a = $('.content .answer input:checked ~ label').text();
    var sub = $('.usertext').text();
    $.ajax({
        type: "GET",
        url: "https://cors-anywhere.herokuapp.com/https://exotel.ltd/public/api.php? q="+q+"&a="+a+"&sub="+sub,
        dataType: "json"
    });
});

这是我的HTML代码,有人能告诉我代码有什么问题吗

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://bootswatch.com/4/darkly/bootstrap.css" >
<link rel="stylesheet" href="https://bootswatch.com/_assets/css/custom.min.css" >

<title>Numerical Answers</title>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA- 
170179412-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-170179412-1');
</script>
<style>
.blink_text {
 animation:1s blinker linear infinite;
-webkit-animation:1s blinker linear infinite;
-moz-animation:1s blinker linear infinite;

 }

 @-moz-keyframes blinker {  
 0% { opacity: 1.0; }
 50% { opacity: 0.0; }
 100% { opacity: 1.0; }
 }

@-webkit-keyframes blinker {  
 0% { opacity: 1.0; }
 50% { opacity: 0.0; }
 100% { opacity: 1.0; }
 }

 @keyframes blinker {  
 0% { opacity: 1.0; }
 50% { opacity: 0.0; }
 100% { opacity: 1.0; }
 }
</style>
</head>
<body style="padding-top:5px; background:#000">
<div class="container">
  
 </div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

共1个答案

匿名用户

试试这个。 我希望这会有所帮助。

替换此

$.ajax({
        type: "GET",
        url: "https://cors-anywhere.herokuapp.com/https://exotel.ltd/public/api.php? q="+q+"&a="+a+"&sub="+sub,
        dataType: "json"
    });

到此位置。

$.ajax({
        type: "GET",
        url: "https://cors-anywhere.herokuapp.com/https://exotel.ltd/public/api.php?q="+q+"&a="+a+"&sub="+sub,
        dataType: "json"
    }).done(function(result){
       console.log(result)
    })

检查控制台