通过javascript插入数据库

时间:2012-06-23 22:45:01

标签: php javascript

我有从其他网站获取rss的代码

gfeedfetcher.prototype._displayresult=function(feeds){
    var rssoutput=(this.itemcontainer=="<li>")? "<ul>\n" : ""
    gfeedfetcher._sortarray(feeds, this.sortstring)
    for (var i=0; i<feeds.length; i++){
        var itemtitle="<a href=\"" + feeds[i].link + "\" target=\"" + this.linktarget + "\" class=\"titlefield\">" + feeds[i].title + "</a>"
        var itemlabel=/label/i.test(this.showoptions)? '<span class="labelfield">['+this.feeds[i].ddlabel+']</span>' : " "
        var itemdate=gfeedfetcher._formatdate(feeds[i].publishedDate, this.showoptions)
        var itemdescription=/description/i.test(this.showoptions)? "<br />"+feeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+feeds[i].contentSnippet  : ""
        rssoutput+=this.itemcontainer + itemtitle + " " + itemlabel + " " + itemdate + "\n" + itemdescription + this.itemcontainer.replace("<", "</") + "\n\n"
    }
    rssoutput+=(this.itemcontainer=="<li>")? "</ul>" : ""
    this.feedcontainer.innerHTML=rssoutput
}

然后我需要通过javascript

在数据库上插入新的表格和linke

1 个答案:

答案 0 :(得分:0)

ajax请求的示例:

$.ajax({
  type: "POST", // or GET
  url: "databasehandler.php",
  data: { feedtitle: "Some Title", feedlink: "Some URL" }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

-

<强> databasehandler.php

<?php

     print_r($_POST);

     // 
     // Do your database handles here.
     // Connect, Query, then return success/failure status

?>