Re: PHP output fails from AJAX call
| From: | Adarsh Sharma | Date: | Thu, 30 Jan 2014 10:27:42 +0000 |
| Subject: | Re: PHP output fails from AJAX call | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-322771@lists.php.net to get a copy of this message | ||
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
> > > >
> > > > <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
>
>
>