在模态中显示来自Ajax .post的订阅

在模态中显示来自Ajax .post的订阅

问题描述:

I have a modal in index.php which when the button to load it is click I need to display the returned data from an ajax post to a PHP file that returns the subscriptions and if a user is subscribed to one it needs to have a unsubscribe button to the right, if the user is not subscribed it should have a subscribe button.

I cant figure out how to return all the subscriptions and display them in the modal from a ajax post. I know i need to send the data back from the php file in Json format, but I do not know how to get all of the subscriptions and if the user is subscribed all in json format

This is where the Ajax call has to happen

    $(document).on('pagebeforeshow','#subscriptions', function(){
        $.post("getsubs.php",function(data))
    });

To further explain better it should look like this when the modal button is click

Subscription A           ButtonToUnsubscribed(user is already subscribed)
Subscription B           ButtonToUnsubscribed(user is already subscribed)
Subscription C           ButtonToSubscribe(Not subscribed to this one)

我在index.php中有一个模态,当单击加载按钮时我需要显示返回的数据 从ajax帖子到返回订阅的PHP文件,如果用户订阅了一个,则需要在右边有一个取消订阅按钮,如果用户没有订阅,则应该有一个订阅按钮。 p>

我无法弄清楚如何返回所有订阅并在ajax帖子的模态中显示它们。 我知道我需要以json格式从php文件发回数据,但我不知道如何获取所有订阅,如果用户以json格式订阅全部 p>

这是Ajax调用必须发生的地方 p>

  $(document).on('pagebeforeshow','#subscriptions',function(){
 $ .post(“  getsubs.php“,function(data))
}); 
  code>  pre> 
 
 

为了进一步说明,点击模态按钮时它应该是这样的 p >

 订阅A ButtonToUnsubscribed(用户已订阅)
订阅B ButtonToUnsubscribed(用户已订阅)
订阅C ButtonToSubscribe(未订阅此订单)
  code>  pre  > 
  div>

create a php file that queries your database and puts all data in a array and with json_encode() it to a json string and print it out.

call this php script with ajax and read the json string put it back in an array. and with some if comparing statement creat the buttons needed

$.ajax({ // ajax call starts
          url: "thephpfile.php",
          data: theData,  ///variable with data to send to php file var1=blabla&var2=blabhsh
          dataType: 'json',
          success: function(data)
          {
             alert(data); //
          }
      });