AriseEVE
AriseEVE

Reputation: 49

send jquery post request and process data

trying to send post request to php file witch resievs feed url from my request parses it and sends back as JSON... so want to get the json it sends and put it into htlm new to js cant make it work.

 $(document).ready(function() {
$(".feed").on("click", function() {
    var feedurl = $(this).attr("value");
    $.post("syndicate.php", {value : feedurl},function(){});
    load();


    });
    function load(){
 $.getJSON("syndicate.php",function(result){

    console.log(result);
    var items = result.items;
    for (var i=0; i<items.length;i++){
        var s = "<table class='dataTable'";
        s += "<tr><td>title</td><td>" + items[i].title + "</td></tr>";
        s += "<tr><td>link</td><td><a href='" + items[i].url + "'>open     link</a></td></tr>";
        s += "<tr><td>content</td><td>" + items[i].content + "</td></tr>";
        s += "</table>";
        $("#widget-content").append(s);
    }

});
}

Upvotes: 1

Views: 280

Answers (1)

AriseEVE
AriseEVE

Reputation: 49

$(document).ready(function() {
$(".feed").on("click", function() {
    var feedurl = $(this).attr("value");
    var response = $.get("../syndicate.php", {
        value : feedurl
    }, function() {
    });

    response.done(function(data) {
        console.log(data);
        var json = JSON.parse(data);
        var items = json.items;

solved! problem was that i wasnt procesing data in same request, i was sending 2 saparate requests 1 for sending data to php and 2 to process respond.

Upvotes: 1

Related Questions