使用AJAX计时器获取“PHP URL内容”

I have many <a href> on my page to generate link like
http://localhost/ozania/order.php?cat_id=DS01

"DS01" is ony an example..

So I want to get values that every link I pressed (in the same page)

function getCAT(){
   $.ajax({
      type: "GET",
    url: "order.php",
    data: {
        cat_id: 'cat_id'
    },
      success: function(response){
       $("#category").text(""+response+"");
       timer = setTimeout("getCAT()",5000);
      }
     });  
  }
  $(document).ready(function(){
   getCAT();
  });

and print the result in <span> like

<span id="category"></span>

but it always printed as nothing....

every i pressed the link, it is not reloading page because i use that script like

<a onclick="window.history.pushState('', '', '?cat_id=<?php echo $row['category_item']; ?>');"><?php echo $row['name_item'];?> </a>

So finally I want to print the link values every link I pressed with AJAX and preventing pages to reload.

I'm not 100% sure I understand what you're asking, but I think you're asking how to add a div with and id "category" somewhere on the page that contains data for each link?

First, html ids should be unique, use a class instead.

Second, if the span does not already exist, you cannot change its text.

Maybe you want to do something more like

$('#somedivthatexists').append('<span class="category">'+response+'</span>');

Also you cannot call a function like this.

Instead try something like

getCat = function(){// the same code in here}

Otherwise you wont be able to call it recursively the way you are trying.

Finally, I don't see an end to the recursion. Maybe you want do loop through all links and call the get cat function on them instead of doing some strange recursion here?

Best of luck.