WS Subscription software
Premium Membership
graphics design php html youtube
Subscribe!
Not a premium user?
Subscriber and get access.
graphics design php html youtube
Live Support
Contact us by live help [photoshop, website design, tutorials]
Not available on weekends

Support our site with a small donation.
This Month: $
Total: $118.89
 
Login or Register to leave username.


ws©

Our Sponsors



PHP Nuke themes, stock photos, icons, drupal themes and more.
Advertise with Western Studios.net
Custom jobs at low cost, free lancers and service buyers.
Free e Cards of holidays, cute animals, nature and more



Latest Jobs





Western Studios :: View topic - How do I get these two functions to work with Ajax, and how
Need Jobs done? Use our brand new Jobs Board to get your projects done at affordable prices.
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups     ProfileProfile   Log inLog in 


How do I get these two functions to work with Ajax, and how



 
Post new topic   Reply to topicprinter friendly version    Western Studios Forum Index -> Web Design
Western Studios

Elite Member
Elite Member
~PHP Nuke User~


Posts: 1660
Next Group: 3340 posts
wsbot wrote:

Hey everyone,



function ajaxFunction(phpFunction){

var ajaxRequest; // The variable that makes Ajax possible!

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
$('.subCat').html(ajaxRequest.responseText);
$('.subCat').ready(function(){
$('.subCat').fadeIn();
});





}
}


var url = "products.php?func=" + phpFunction;

ajaxRequest.open("GET", url, true);
ajaxRequest.send(null);

}


This function works great, and has no problems. But if I add:



function refreshProduct(idNum, phpFunction){

var ajaxRequest; // The variable that makes Ajax possible!

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
$('.' + idNum).empty();
$('.' + idNum).html(ajaxRequest.responseText);

});





}
}


var url = "products.php?func=" + phpFunction + "&idNum=" + idNum;

ajaxRequest.open("GET", url, true);
ajaxRequest.send(null);

}


When I try to execute ajaxFunction('returnAllProducts') I get:



    syntax error

});\n


from



   $('.' + idNum).html(ajaxRequest.responseText);


}); <<<----


and



ajaxFunction is not defined

javascript:ajaxFunction('returnAllProducts')()


So my questions are:



a) how do I convert this over to jquery? I've read over some jquery ajax tutorials, but I wasn't able to make the connection how to do what I am doing here.
b) How do I get both functions to work? I know the PHP behind them works fine, but I can't even test if refreshProduct() works properly right now.



View Solution
How do I get these two functions to work with Ajax, and how

Posted: Mon Feb 08, 2010 1:01 pm

Post new topic   Reply to topic    Western Studios Forum Index -> Web Design All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Forums ©