• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help me with my Ajax issue

#1
[eluser]Unknown[/eluser]
I am an Ajax newbie and all I am trying to do is for someone to submit a form and then be notified periodically while processing is being done. So when they submit form process_data gets called but I can never get the process status to work.



//DOES NOT WORK!!!!

Code:
function update_status($status)
    {
$objResponse = new xajaxResponse();
$objResponse->assign("process_status", "innerHTML", $status);
return $objResponse;
        
    }
    

    function process_data($form_data)
    {
               $url="";
        $url=$form_data['url'];
               $this->myclass->update_status("analyzing: ".$url);
              
                 //do some processing......
                //update status
                   $this->myclass->update_status("processing complete");
}


//////////////////////////////////////HOWEVER THIS WORK!!

Code:
function process_data($form_data)
    {
               $url="";
        $url=$form_data['url'];
            
$objResponse = new xajaxResponse();
$objResponse->assign("process_status", "innerHTML", "analyzing: ".$url);
return $objResponse;
          
}

#2
[eluser]slowgary[/eluser]
A few tips for getting responses to your questions:

1. Make sure you're posting to the relevant forum/topic. This is a codeigniter forum, but your post doesn't have anything to do with codeigniter, so you'd probably have better luck on a xajax forum.

2. Don't make things more difficult for the people who you need help from. In your case, I would consider formatting your posted code consistently so that it looks less confusing for the people who would help you.


You should format your code like this:

Code:
function update_status($status)
{
     $objResponse = new xajaxResponse();
     $objResponse->assign("process_status", "innerHTML", $status);

     return $objResponse;
}

function process_data($form_data)
{
     $url=$form_data['url'];
     $this->myclass->update_status("analyzing: ".$url);
              
     //do some processing......
     //update status
     $this->myclass->update_status("processing complete");
}

and this:
Code:
function process_data($form_data)
{
     $url=$form_data['url'];
            
     $objResponse = new xajaxResponse();
     $objResponse->assign("process_status", "innerHTML", "analyzing: ".$url);

     return $objResponse;    
}

Also, it would help if we had more details about the problem. You say the first bit of code doesn't work, but the second one does. Why not just use the second one?

What do you mean when you say, "I am trying to do is for someone to submit a form and then be notified periodically while processing is being done"??

Are you trying to notify the user of something, or do you want the site to be notified periodically while the form is being completed. What do you mean by "periodically"?? Do you want something to occur at a timed interval, or based on an event?

I have a bunch of experience with JavaScript and AJAX, and I highly recommend using the jQuery framework as it makes everything very easy. I don't really understand your code though. You're showing us the PHP - is this the code that your AJAX request calls upon? What about the client side code, can we see that too?

It's very difficult when you post 20 lines of code but only two incomplete sentences to describe what problems you're having.

One thing I know for sure is that if you are expecting your client side code to get data back from an AJAX request, that data must be printed to the screen, thus sending it back to the client. I don't see any echo statements anywhere. Maybe your 'update_status' function should echo the $objResponse instead of returning it? I have no experience with this 'xajax' library, so maybe I'm missing something.

Good luck.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.