开发者

How to use the xmlhttprequest to make a new child node appear in the html with node data from php script

I have a javascript function assigned to a button which when clicked removes nodes from a div, each node in the div being

<p class="line"><a href="...">example</a></p> 

which works fine. This uses the removeChild and lastChild functions of javascript. What I want to do is to be able to add nodes onto the end of the node list in the div, where the node content (the link) is taken from the php script on my server.

I can get up to the point where I say

xmlObj.open ('GET', '/ajax?action=boxcontent&i='+i', true);
xmlObj.send ('');

That is after declaring the request object and checking it's in the 4th readystate.

But that is far as I can get. I know basic php, so I need a php file called boxcontent.php and in it I need to have the node information that I want to put i开发者_如何学Cnto the div. There are also several divs on the page which is why I put the 'i' in the GET request link, so I can specifiy which once I want the information for, but I will worry about that later... I want to get one box working first.

If someone could be kind enough to give me guidance I would be most appreciative.


This will make the request to the URL you specify and show the response in an alert message box (add it between the xmlobj.open(...) and xmlObj.send(...) lines):

xmlObj.onreadystatechange = function() {
    if(xmlObj.readyState == 4) {
        alert(xmlObj.responseText);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜