0

I need a Drupal form to submit a file to an external server using ajax. I have done the form using Form API and I am able to submit it via Ajax, But the Drupal throbber never stops and I am not able to get the returned value. But in firebug I can see it to be returned.

My Code:

function upload_video_episode($form, &$form_state){

     $form['files'] = array(
        '#type' => 'file',
        '#title' => t('Video'),
        '#description' => t('Upload a file, allowed extensions: mov, mp4, avi, mkv'),
      );

     $form['submit'] = array(
           '#type' => 'submit',
           '#value' => t('Submit'),
           '#ajax' => array( 
           'path' => url('http://web.com/test.php', array('external' => true)),
           'callback' => 'upload_video_test',
           ),
      );

    $form['#action'] = url('http://198.199.95.235:8080/dev/test.php', array('external' => true));
    return $form;
}

function upload_video_test(){
    return "Done!";
}

The throbber just keep rotating non-stop.

Once submitted the throbber keep rotating non-stop

However, in firebug I can see the form have been submitted and values returned.

From Net Tab of Firebug.

Console seems to be showing some error, possibly related to Non-Origin. But in my case the data is already submitted.

Error: Permission denied to access property 'document'

Error in console.

  • Is what I have done so far correct?
  • I want to get the returned value and store it in a hidden form field or something.
  • Or is Drupal Form API not capable of handling external urls?

Any help would be highly appreciated.

1

Sounds like it's spinning forever because of the js error.

Where is the error occurring? In jQuery library?

If so use an uncompressed version of jQuery and it may be easier to debug.

Maybe even temporarily hack jQuery core to remove error and see if that fixed your problem before spending time figuring out how to fix it properly...

1
  • It seems to be due to same origin policy or something. That what I get when I google. But its weird as the action is technically getting complete behind the scene. – esafwan Apr 4 '14 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.