douyuai8994 2014-10-06 17:40
浏览 21
已采纳

在模态中显示来自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)
  • 写回答

1条回答 默认 最新

  • duanbanzhi4419 2014-10-06 17:55
    关注

    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); //
              }
          });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?