Page 1 of 1

php and ajax problem

Posted: Wed Mar 25, 2009 4:11 am
by shaqa
i have a script which work with ajax, current option doesnt add campaign at mysql and list it.

Code: Select all

<div id="head">
      <h1>';
  if ($_SESSION['ff_loggedin'] == 'yes')
  {
    echo '<div id="campaign">';
    echo '<s';
    echo 'elect name="campaign" onchange="campaignselect(this.options[this.selectedIndex].value, ';
    echo $_SESSION['ff_user'];
    echo ')">';
    if (getcampaign ($_SESSION['ff_user']) != 'no')
    {
      echo '<option disabled="disabled" selected="selected">';
      echo getcampname ($_SESSION['ff_user']);
      echo '</option>';
    }
    else
    {
      echo '<option disabled="disabled" selected="selected">Select a Campaign</option>';
    }
 
    echo campaignlist ($_SESSION['ff_user']);
    echo '<option value="new">>Create a new Campaign</option></select></div>';
  }
 
  echo '</h1>
</div>
 
campaign.js

Code: Select all

// JavaScript Document
function campaignselect(val, owner){
    if(val == "new"){
        var name = prompt("Enter a name for your new campaign", "Your campaign name...");
        addCamp(name, owner);       
    } else {
        selectCamp(val);
    }
}
 
var xmlHttp
function addCamp(name, owner)
{ 
xmlHttp=gGetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 name2 = name;
var url="index.php"
url=url+"?action=campaigns&name="+name+"&owner="+owner+"&act=insert"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=addCampaign 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function addCampaign() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
    alert("Campaign '" + name2 + "' added!");
    window.location.reload(true);
 } 
}
 
function selectCamp(val)
{ 
xmlHttp=gGetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 name2 = name;
var url="index.php"
url=url+"?action=campaigns&camp="+val+"&act=select"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=selCampaign 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function selCampaign() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
    window.location.reload(true);
 } 
}
 
{ 
 
}
 
function gGetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  } 
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
 
function campswitcher(ownerid, campid){
    owner = ownerid;
    image = document.getElementById(campid);
    theid = campid;
    if(image.src.indexOf("enabled") > -1){
        method = 'disable';
        changethecamp(method, image);
    } else if(image.src.indexOf("disabled") > -1){
        method = 'enable';
        changethecamp(method, image);
    }
}
 
function changethecamp(method, image)
{ 
xmlHttp=gGetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="index.php"
url=url+"?action=campaigns&method="+method+"&camp="+theid+"&owner="+owner+"&act=status"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=abcsstateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function abcsstateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 if(method == 'disable'){
     image.src = "css/ol_admin_images/disabled.png";
     } else if(method == 'enable'){
     image.src = "css/ol_admin_images/enabled.png";
     }
 } 
}
 
 
 
function campdelete(ownerid, campid, i){
    owner = ownerid;
    theid = campid;
    row = i;
 
    table = this.document.getElementById('list-camp');
 
        delthecamp();
    
}
 
function delthecamp()
{ 
xmlHttp=gGetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="index.php"
url=url+"?action=campaigns&camp="+theid+"&owner="+owner+"&act=delete"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=delsstateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function delsstateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
        
    table.deleteRow(row);
    update = table.rows.length;
    white = 1;
    for(i=0; i<update; i++){
        row = table.getElementsByTagName("tr")[row];
        if (white == 1){
            row.style.backgroundColor = "#E0E2F3";
            white = 0;
        } else {
            row.style.backgroundColor = "#FFFFFF";
            white = 1;
        }   
    }
}
}

Re: php and ajax problem

Posted: Wed Mar 25, 2009 4:33 am
by shaqa
would be better if somone can help me creating simply php and html add/list option

Re: php and ajax problem

Posted: Wed Mar 25, 2009 5:18 am
by php_east
that is a lot of work. and also, it looks like there is already a nice ajax, so why go back to old html. maybe better if you repair the ajax ? at least its all already done.

Re: php and ajax problem

Posted: Wed Mar 25, 2009 12:53 pm
by shaqa
any suggestion?