Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

AJAX, response headers are not sent by PHP script! -


i'm banging head hours now. have select option updates database using ajax (at least it's trying to!). happens while running php script directly params required database gets updated not when running indirectly through ajax, instead 3 times alert("there problem in returned data:\n"); , gets updated. javascript on <head> , not in external file. here goes:

javascript:

function updatehub(){       if (window.xmlhttprequest){         // code ie7+, firefox, chrome, opera, safari           xmlhttp=new xmlhttprequest();       }else{         // code ie6, ie5           xmlhttp=new activexobject("microsoft.xmlhttp");       }       xmlhttp.onreadystatechange = function(){          if (xmlhttp.readystate==4 && xmlhttp.status==200){              document.getelementbyid("hubinfo").innerhtml=xmlhttp.responsetext;          }else{              alert("there problem in returned data:\n");          }       }       var prefhub = document.getelementbyid("prefhub");       var hubid = prefhub.options[prefhub.selectedindex].value;       xmlhttp.open("get","updatehub.php?hubid="+hubid,true);       xmlhttp.send();   } 

updatehub.php:

session_start(); include '../../../common/config.php'; $hubid = ''; if(isset($_post['hubid'])){     $hubid = strip_tags(mysql_real_escape_string(trim($_post['hubid']))); }elseif(isset($_get['hubid'])){     $hubid = strip_tags(mysql_real_escape_string(trim($_get['hubid']))); } mysql_query("update prefs set hubid='$hubid' userid = '".$_session['userid']."'") or die(mysql_error()); if(mysql_affected_rows()){     echo "updated"; }else{     echo 'error'; } return $hubid; 

and html:

<form action="" method="post" onsubmit="updatehub();">     <select name="prefhub" id="prefhub">         <option value="43">opt1</option>         <option value="64">opt2</option>         <option value="30">opt2</option>      </select>      <input type="submit" name="update" value="update hub"/> </form> <div id="hubinfo"></div> 

instead 3 times alert("there problem in returned data:\n");

if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("hubinfo").innerhtml=xmlhttp.responsetext; } else{ alert("there problem in returned data:\n"); } 

this means see alert. since other xmlhttp.readystate values else {} block executed.


the xmlhttprequest object can in several states. readystate attribute must return current state, must 1 of following values:

unsent (numeric value 0)

the object has been constructed.  

opened (numeric value 1)

the open() method has been invoked. during state request headers can set using setrequestheader() , request can made using send() method.  

headers_received (numeric value 2)

all redirects (if any) have been followed , http headers of final response have been received. several response members of object available.  

loading (numeric value 3)

the response entity body being received.  

done (numeric value 4)


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -