Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-03-2008, 08:50 PM
Member
 
Join Date: Feb 2008
Posts: 46
Question Small Ajax Example

Hi,

I need to do one small ajax call using ZF. I tried in our normal method. That is one php file and whne onchange one list box value, i will call the JS function and it will call the Ajax function and send the request. But i am getting "Error". How to do Ajax calling? Give me a small example for this.

- mugesh.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-03-2008, 10:12 PM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

Well these are my thoughts, which may be wrong, but I have been using JQuery to do AJAX requests. AJAX is more of a front-end realm so it really doesn't have much to do with PHP. The only thing AJAX related that Zend can do is Zend_Json

One thing you might want to be doing is turning off the viewRenderer?

Quote:
Originally Posted by murugesanme View Post
Hi,

I need to do one small ajax call using ZF. I tried in our normal method. That is one php file and whne onchange one list box value, i will call the JS function and it will call the Ajax function and send the request. But i am getting "Error". How to do Ajax calling? Give me a small example for this.

- mugesh.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-04-2008, 08:20 PM
Member
 
Join Date: Feb 2008
Posts: 46
Question

I dont understand that JSON . can you able to give me some sample file to upload and to check. so that i can gothrough both and get some solution or give me some usefull link to Learn Ajax with ZF and ZF Json with example.

- Thanks

-Mugesh.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-05-2008, 03:25 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

ZF JSON is for preparing and parsing JSON style data (which is just an alternative to XML).

But as far as AJAX goes, the code you use depends on the JS code... are you using a library (jquery, prototype.js, mootools) or do you have custom code to do your AJAX calls?

That's the first thing to figure out.

Also, how is reporting the error? JS or ZF? If its JS, then look there. If its ZF, then more than likely the code your ajax is trying to call has a bug.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-05-2008, 06:28 PM
Member
 
Join Date: Feb 2008
Posts: 46
Question

It is a ZF error only. While requesting a page, i am getting this error.
And about the Ajax, i am using the normal way methods. Eg: xmlHttp obj creation , onreadystatechange , another method call and which will check the response status and returen the responseText to the current page. Is there any other way to implement Ajax with ZF?

- plz give me some idea to do this.
-mugesh.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-05-2008, 07:23 PM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

what is the error message you are getting?


Quote:
Originally Posted by murugesanme View Post
It is a ZF error only. While requesting a page, i am getting this error.
And about the Ajax, i am using the normal way methods. Eg: xmlHttp obj creation , onreadystatechange , another method call and which will check the response status and returen the responseText to the current page. Is there any other way to implement Ajax with ZF?

- plz give me some idea to do this.
-mugesh.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-06-2008, 03:54 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

Yeah, the error in ZF is probably a bug in your PHP code.

Can you get the ZF method to return the responseText without error when you try to run it outside of an AJAX request?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-10-2008, 07:35 AM
Member
 
Join Date: Feb 2008
Posts: 46
Question

i am not using any of the ZF method to invoke ajax method.Onclick of one button, i am calling the ajax method and the ajax method will send request to "ajax.php?id=3&val=10" page with parameter.

xmlHttp.open("GET","ajax.php?id=3&val=10",true)
xmlHttp.send(null);

Here, what i want is, how the request should be?
like "ajax.php?id=3&val=10" ? or our standard ZF requesting like
"index.php/controller/action/id/3/val/12" ?

I tried both the ways. But not getting. Is there any other method to send ajax request ? or How i can send request to JSON formate or anything else?

-mugesh.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-10-2008, 02:22 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

Can you run either call in the browser?

ajax.php?id=3&val=10 OR index.php/controller/action/id/3/val/12 ?

In other words, can the script that will be returning data to your ajax call be run in the browser, and give you the intended result? I'd debug the PHP script you're calling with ajax first. If you can get this working, then take a look at it when its called via AJAX.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 03-11-2008, 04:57 AM
Member
 
Join Date: Feb 2008
Posts: 46
Question

Actually i am calling the ajax function during onClick of a button. That ajax function will request my ajax php file with the request "ajax.php?id=3&val=10". Where this ajax.php file will have only one <?php echo 'hai'; ?> code. So, when i get the response in my current page, it would alert "hai". So, I tried like this. That time i got an error from my Exception function present in my php file. Then i tried to call thru ZF request. So, can anyone plz tell me how i can call the ajax function ? and how i can take the response "hai".?

or give ur personal chat id or messenger id . So that i can clear about my doubt and get some solution.
- mugesh
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:47 AM.