Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

Http-post mehod is not working in Javascript

$
0
0

When i do a http-post request from a html form it was working. But when i do this using javascript it throw a error like this

Access to XMLHttpRequest at 'https://www.something.php' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I inspect element and copy as cUrl and try in Postman and it working.Please help if i am doing any mistake

my html code

<html>
<head>

<form action="https://www.something.php" method="POST">
  <div class="container" style="width:100%;">
    <center></center>
  </div>
  <div class="container" style="width:100%;">
    <label for="userId"><b>UserId</b></label>
    <input type="number" placeholder="Enter Your User Id" name="userId" autofocus required>

    <label for="categoryId"><b>categoryId</b></label>
    <input type="number" placeholder="Enter categoryId" name="categoryId" required>

    <button type="submit">GET DATA</button>
  </div>

</form>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>

<script>

  $(function() {
    var people = [];

    var userId=$('#userId').val();
    var categoryId=$('#categoryId').val();

    $.post('https://www.something.php',{userId:5 , categoryId:50},function(data) {
      $.each(data.video, function(i, f) {

        var link = "https://www.youtube.com/embed/"+ f.video;       
        var tblRows = "<tr>" +
          "<td>" + f.videoName + "</td>" + "<td>" + f.date + "</td>" + "<td>" + f.time + "</td>"  +
          "<td>" + f.videoDuration + "</td>" + "<td>" + f.liveStatus + "</td>" + "<td><a target='_blank' href='"+link+"'>"+link+"</a></td>" + "</tr>";
        $(tblRows).appendTo("#userdata tbody");

      });
    });
});
</script>

</head>
<body>

  <div class="wrapper">
    <div class="profile">
      <table id= "userdata" width="50%" border="2">
        <thead>
          <th>VIDEO NAME</th>
          <th>DATE</th>
          <th>TIME</th>           
          <th>DURACTION</th>
          <th>LIVE STATUS</th>
          <th>LINK</th>
        </thead>
      <tbody>
      </tbody>
    </table>

  </div>
</div>
</div>
</html>


Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>