2013-01-02 42 views
0

当关闭在WordPress中ThickBox的,我想首先通过ThickBox的选择的图像添加到屏幕(工作),然后运行一个小的AJAX程序更新的选项时数据库(导致错误)。NS_ERROR_XPC_BAD_CONVERT_JS试图调用一个AJAX功能

不过,我得到的错误NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument,我不知道为什么。

目前,我所做的只是试图测试AJAX函数是否已被伪装起来,所以所有的PHP函数都在做echo 'Working!';,所以我相当肯定问题出在JS的某处,相反以什么由PHP返回。但是,评论AJAX调用意味着错误不会出现。

没有人有任何故障排除建议?我现在非常失望,看看现在在哪里。谢谢。

jQuery(document).ready(function($){ 

    window.send_to_editor = function(html){ 

     /** Grab the image URL and image ID */ 
     var image_url = $('img', html).attr('src'), 
      classes = $('img', html).attr('class'), 
      id = classes.replace(/(.*?)wp-image-/, ''); 

     /** Add the imgae ID to a hidden field, so that it can be saved */ 
     $('#office-image input#image-id').val(id); 

     /** Remove the Thickbox */ 
     tb_remove(); 

     /** Place the image src in the hidden image, and then show the image */ 
     $('#office-image img#image-preview').attr('src', image_url); 
     $('#office-image img#image-preview').css('display', 'block'); 
     $('#office-image img#image-preview').css('margin-bottom', '5px'); 

     /** Check to see if the user is editing an Office, and if they are, update the Image in the database */ 
     if($('#dd-options-edit-office-page').length) { 

      /** Set the params for passing to the AJAX function */ 
      data = { 
       security: $('input#_wpnonce', '#dd-options-edit-office-page'), 
       action: 'update-office-image' 
      }; 

      $.post('admin-ajax.php', data, function(response){ 

       alert(response); 

      }); 

     } 

    } 

}); 

感谢,

回答

1

在此请看:

data = { 
       security: $('input#_wpnonce', '#dd-options-edit-office-page'), 
       action: 'update-office-image' 
      }; 

data.security包含一个jQuery对象,它不能发送这个对象。

我猜你想发送的输入值:

data = { 
       security: $('input#_wpnonce', '#dd-options-edit-office-page').val(), 
       action: 'update-office-image' 
      }; 
+0

感谢长久,我担心它会是一些愚蠢这样! –