Re: PHP output fails from AJAX call
| From: | Domain nikha . org | Date: | Thu, 30 Jan 2014 11:35:13 +0000 |
| Subject: | Re: PHP output fails from AJAX call | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-322776@lists.php.net to get a copy of this message | ||
Adarsh Sharma am Donnerstag, 30. Januar 2014 - 12:25:
> There is no error in mysql queries i.e i told earlier if u opens the below
> link directly :
>
> *http://db11.app.com/project/ajaxex.php?q=133
> <http://db11.app.com/project/ajaxex.php?q=133>*
>
> you will get the complete report so no issues with ajaxex.php.
>
> but i need the same after clicking on Weekly Report Command button when i
> opened
>
>
>
> *http://db11.app.com/project
> <http://db11.app.com/project/ajaxex.php?q=133> and
> chooses one user.*
>
> *Thanks*
>
>
> On Thu, Jan 30, 2014 at 4:45 PM, Domain nikha.org <mail@nikha.org> wrote:
>
> > Adarsh Sharma am Donnerstag, 30. Januar 2014 - 11:36:
> > > PFA
> > >
> > > Thanks
> > >
> > >
> > > On Thu, Jan 30, 2014 at 3:57 PM, Adarsh Sharma <eddy.adarsh@gmail.com
> > >wrote:
> > >
> > > > Agreed Nikha. Valid point. See i tested by added one line in my code :
> > > >
> > > >
> > > > var users = document.getElementById('users').value;
> > > > var queryString = "?users=" + users ;
> > > > * document.write(users); *
> > > > ajaxRequest.open("GET","ajaxex.php?q="+users,true);
> > > > ajaxRequest.send();
> > > >
> > > > When i run it , it gives me exact value of the user which i chooses..
> > If my
> > > > user variable is empty then my output should be blank. Also,
> > > >
> > > > http:///db11.app.com/project/ajaxex.php?q=133
> > > >
> > > > It the end of the above link , you can see the exact value of user.
> > > >
> > > > Thanks
> > > >
> > > >
> > > > On Thu, Jan 30, 2014 at 3:50 PM, Domain nikha.org <mail@nikha.org>
> > wrote:
> > > >
> > > >> Adarsh Sharma am Donnerstag, 30. Januar 2014 - 10:39:
> > > >> > Thanks Nikha but its already dere :
> > > >> >
> > > >> > <html>
> > > >> > <head>
> > > >> > <script>
> > > >> > function week_report_fun(){
> > > >> > 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;
> > > >> > }
> > > >> > }
> > > >> > }
> > > >> > ajaxRequest.onreadystatechange = function(){
> > > >> > if(ajaxRequest.readyState == 4){
> > > >> > var ajaxDisplay = document.getElementById('ajaxDiv');
> > > >> > ajaxDisplay.innerHTML = ajaxRequest.responseText;
> > > >> > }
> > > >> > }
> > > >> > var users = document.getElementById('users').value;
> > > >> > var queryString = "?users=" + users ;
> > > >> > //document.write(queryString);
> > > >> >
> > > >> > ajaxRequest.open("GET","ajaxex.php?q="+users,true);
> > > >> > ajaxRequest.send();
> > > >> > }
> > > >> >
> > > >> > </script>
> > > >> > </head>
> > > >> > <body>
> > > >> >
> > > >> > <form>
> > > >> > User : <select id="users">
> > > >> > <option value="">Select a user</option>
> > > >> > <option value="133">a.v</option>
> > > >> > <option value="168">ad</option>
> > > >> > </select>
> > > >> > <input type='button' onclick="week_report_fun()"
> > > >> > value='Weekly Report'/>
> > > >> > </form>
> > > >> > <br>
> > > >> >
> > > >> > </body>
> > > >> > </html>
> > > >> >
> > > >> >
> > > >> > Sorry My bad , i didn't mention the complete program in my first
> > mail
> > > >> >
> > > >> >
> > > >> > Thanks
> > > >> >
> > > >> > On Thu, Jan 30, 2014 at 2:36 PM, Domain nikha.org
> > > >> > <mail@nikha.org>
> > > >> wrote:
> > > >> >
> > > >> > > Adarsh Sharma am Donnerstag, 30. Januar 2014 - 07:27:
> > > >> > >
> > > >> > > > Hi,
> > > >> > > >
> > > >> > > > I am using AJAX and php for creating a small UI that
> > > >> > > > retrieves
> > data
> > > >> from
> > > >> > > > mysql upon clicking on one button. But i clicked on that ,
> > nothing
> > > >> is
> > > >> > > > happening. Below is my index.html :
> > > >> > > >
> > > >> > > > *-- index.html *
> > > >> > > >
> > > >> > > > <html>
> > > >> > > > <head>
> > > >> > > > function week_report_fun(){
> > > >> > > > var ajaxRequest;
> > > >> > > > ---
> > > >> > > > ---
> > > >> > > > --
> > > >> > > >
> > > >> > > > ajaxRequest.open("GET","ajaxex.php?q="+users,true);
> > > >> > > > ajaxRequest.send();
> > > >> > > > }
> > > >> > > >
> > > >> > > > </script></head><body>
> > > >> > > > <form>
> > > >> > > > User : <select id="users"
> > > >> > > > onchange="week_report_fun()">
> > > >> > > > <option value="">Select a user</option>
> > > >> > > > <option value="133">av</option>
> > > >> > > > <option value="168">ad</option>
> > > >> > > > <option value="78">so</option>
> > > >> > > > <option value="239">ak</option>
> > > >> > > > </select></form><br>
> > > >> > > > <div id="txtHint"><b>Person info will
> > > >> > > > be listed here.</b></div>
> > > >> > > > </body></html>
> > > >> > > >
> > > >> > > > *Access Log Output :-*
> > > >> > > >
> > > >> > > > 1.4.15.25 - - [30/Jan/2014:06:05:52 +0000] "GET
> > > >> /project/ajaxex.php?q=133
> > > >> > > > HTTP/1.1" 200 5323
> > > >> > > > "http://db11.app.com/project/" "Mozilla/5..0
> > > >> > > (Macintosh;
> > > >> > > > Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko)
> > > >> > > > Chrome/32.0.1700.102 Safari/537.36"
> > > >> > > > 1.4.15.25 - - [30/Jan/2014:06:06:13 +0000] "GET
> > > >> > > /project/ajaxex.php?q=133
> > > >> > > > HTTP/1.1" 200 5323 "-" "Mozilla/5.0
> > > >> > > > (Macintosh; Intel Mac OS X
> > > >> 10_9_1)
> > > >> > > > AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102
> > > >> > > Safari/537.36"
> > > >> > > >
> > > >> > > > No errors in error.log.
> > > >> > > >
> > > >> > > > Strange thing if i directly open below link in the browser,
> > report
> > > >> is
> > > >> > > > coming and i am able to see in the browser :
> > > >> > > >
> > > >> > > >
> > > >> > > > *http:///db11.app.com/project/ajaxex.php?q=133
> > > >> > > > <ÝÝfçà(!+|+
> > > >> > > > `http://db11.app.com/project/ajaxex.php?q=133>*
> > > >> > > >
> > > >> > > > It means my ajaxex.php is fine and no issues but dont
> > > >> > > > understand
> > > >> why it
> > > >> > > is
> > > >> > > > not working as expected after clicking on button.Please let
> > > >> > > > me
> > know
> > > >> if i
> > > >> > > am
> > > >> > > > missing something.
> > > >> > > >
> > > >> > > >
> > > >> > > > Thanks
> > > >> > > >
> > > >> > > Hi Adarsh!
> > > >> > > Yes, you are missing something: The opening <script> tag in
> > > >> > > your
> > html
> > > >> head!
> > > >> > > without that, your ajax code is simply ignored.
> > > >> > >
> > > >> > > Hope it helps
> > > >> > > Niklaus
> > > >> > >
> > > >> >
> > > >> OK!
> > > >> Consider to give names to the <form> and the <select> tag.
> > > >> FI:
> > > >> <form name="selector">
> > > >> <select name="user">
> > > >>
> > > >> Then you can point to them in your javascript like this:
> > > >> var users = document.selector.user.value
> > > >>
> > > >> Actualy, your users variable is just empty, what is not an error. So
> > you
> > > >> have no error reported.
> > > >>
> > > >> Niklaus
> > > >>
> >
> > Hard case, I think!
> > Thanks for your PHP script. What happens, if you run it without the
> > preliminary javascript UI?
> >
> > The database query looks very complicated. I'm not realy an expert in
> > mysqli. But as far as I experienced that, "SELECT" expects a _comma
> > separated_ list of valid expressions before the "FROM" keyword. You have
> > blanks there, like "us.login user" and others. Are you shure about this?
> >
> > mysqli_query() does not return error messages, so you have blanc pages if
> > it failes,
> >
> > I think, you should have a look to the Mysql manual...
> > Niklaus
> >
>
I'm sorry, I cannot test your site: DNS failure!
host reports: "Host db11.app.com not found: 3(NXDOMAIN)"
If ist works for You, the error must be on the ajax side. Personaly I was never using ajax. So:
refer to the ajax Manual :-)
Thanks, Niklaus