Jump to content

Div posting to Ajax


Recommended Posts

OK, I've left the login thing for now haha

 

I need to work something out for the products section as you probably saw I was having issues with loops last time. Fixed that  :)

But I just need to know the best way to do this. And if this will even work 0.o

 

<script type="text/javascript" language="javascript">
<!--

function change(catagory, paction, ID) {

document.getElementById('productsDIV').innerHTML = "<img src='images/loading.gif' alt='Loading Please Be Patient' />"

//cant work out how to set the variables for this

http.open('POST', 'testhelp.php?paction='+paction+'&catagory='+catagory);
http.onreadystatechange = ajaxction;
http.send(null);
}

function ajaxction() {
if(http.readyState == 4){ 
var newcontent = http.responseText;
document.getElementById('productsDIV').innerHTML = 'There Was An Error :[';
}
else{
document.getElementById('productsDIV').innerHTML = ''+newcontent+'';
}
//-->
</script>

 

On the page will be a container div which will have LOTS of little divs inside it might make it a table either way! and I cant work out how I'd get an onclick function on the divs to send a variable to the Ajax and reload the page according to what "link" was pressed.

 

Not even sure if this is going to work I'm a total newbie with Ajax usually just use Iframes but Ajax will look better on the ol' CV  :P

 

and just so you know there are multiple functions in my PHP class controlled with a switch so I need someway of getting the accoriding next action along with whatever catagory is clicked (the section I'm on). But for now just getting a div to post to Ajax will help me loads I can work stuff out from there.

 

<3 Google hehe  :)

Link to comment
https://forums.phpfreaks.com/topic/114737-div-posting-to-ajax/
Share on other sites

Check out w3schools' AJAX tutorial(s).

 

And the first thing I noticed by glancing through the script, is that you never define what 'http' is. Looking through the tutorial I linked to will show you the basic setup of an ajax app :)

 

FlyingIsFun1217

Link to comment
https://forums.phpfreaks.com/topic/114737-div-posting-to-ajax/#findComment-590181
Share on other sites

Wow seems like I managed to reply to the wrong thread earlier...

 

http://www.phpfreaks.com/forums/index.php/topic,206137.msg938757.html#msg938757

 

 

Anyway, I must agree with FlyingIsFun1217.  Hopefully an example script will help you grasp the basics, but you really should learn it from the ground up.

Link to comment
https://forums.phpfreaks.com/topic/114737-div-posting-to-ajax/#findComment-590215
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.