1

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>
5
  • probably val() instead of text() Commented Jun 22, 2020 at 8:26
  • What error is being returned. Look at the dev console. Commented Jun 22, 2020 at 8:28
  • There is no error i was not show data on my html website it does't show any error but also not working. Commented Jun 22, 2020 at 8:32
  • The url has no protocol. And why is there a space after ?? Commented Jun 22, 2020 at 8:34
  • Also shared the html code now you guys can understand my Problem batter Commented Jun 22, 2020 at 8:50

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Brother do i have to use any php code to fetch the data from the js file??
i am making an extension to copy data from one website and post it to other and not familiar with ajex
works great! even though i have to screen capture as message in console will disappear quickly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.