简体   繁体   中英

How to get request url in a jQuery $.ajax request

I am working on a extension by using get function but i am unable to fetch data from the web and post it on other web i am unable to sent data from js file to html can anybody help me how to make this thing work.

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"
    });
});

This Is My HTML code can anybody tell me what is wrong with the code

<!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>

Try this. I hope this will help.

Replace this

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

Into this.

$.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)
    })

Check your console

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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