获取发出$ .post请求的页面的节点ID(Getting the node ID of a page making a $.post request)
所以在我的模块中,我正在为一个drupal菜单回调制作$ .post。 有没有办法找出用户在服务器端上执行$ .post的节点? 谢谢。
示例代码不起作用:
function module_menu() { $items = array(); $items['checkNID'] = array( 'title' => 'Check Users', 'page callback' => 'NIDCheck', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); return $items; } function NIDCheck (){ $result = array(); $result['nid'] = arg(1); return drupal_json($result); } $.post('/checkNID/', function(data) { console.log(data); // this should return the nid }, "json");
So in my module I'm making a $.post to a drupal menu callback. Is there some way to find out which node the user is doing the $.post from on serverside? Thanks.
Sample code that doesn't work:
function module_menu() { $items = array(); $items['checkNID'] = array( 'title' => 'Check Users', 'page callback' => 'NIDCheck', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); return $items; } function NIDCheck (){ $result = array(); $result['nid'] = arg(1); return drupal_json($result); } $.post('/checkNID/', function(data) { console.log(data); // this should return the nid }, "json");
原文:https://stackoverflow.com/questions/4406168
更新时间:2021-11-16 20:11
最满意答案
resp = (T) request.get();
阻止UI线程。 您应该在
onPostExecute()
处理任何响应,而不强制主线程等待doInBackground()
完成。resp = (T) request.get();
is blocking UI thread. You should handle any response in
onPostExecute()
without forcing the main thread to wait fordoInBackground()
to finish.
相关问答
更多-
/** * this class performs all the work, shows dialog before the work and dismiss it after */ public class ProgressTask extends AsyncTask
{ public ProgressTask(ListActivity activity) { this.activity = activity; ... -
问题出在这一行: getGeneralitaTask.get(); 它将导致当前线程等待任务完成。 The problem is on this line: getGeneralitaTask.get(); It will cause the current thread to wait for the task to complete.
-
您正在尝试对包含"Loaded "+progress+"%"的字符串执行parseInt 。 它不能工作。 尝试这个 : publishProgress(""+progress); // [...] protected void onProgressUpdate(String... progress) { Log.d("ANDRO_ASYNC", "Loaded " + progress[0] + "%"); pd.setProgress(Integer.parseInt(progres ...
-
依次运行AsyncTask,并在preExecute或postExecute上更新对话框。 并在doInBackground中编写for循环,其中i是执行任务的指示器。 Run AsyncTask successively, one by one, and update your dialog on preExecute or postExecute. And write your for loop in doInBackground, where i is a indicator what task ex ...
-
ProgressDialog后期显示,使用AsyncTask延迟活动(ProgressDialog late showing, activity lag using AsyncTask)[2023-09-15]
resp = (T) request.get(); 阻止UI线程。 您应该在onPostExecute()处理任何响应,而不强制主线程等待doInBackground()完成。 resp = (T) request.get(); is blocking UI thread. You should handle any response in onPostExecute() without forcing the main thread to wait for doInBackground() to ... -
直到AsyncTask完成后才会显示ProgressDialog(ProgressDialog does not display until after AsyncTask completes)[2023-06-15]
不要从doInBackground() 。 首先,它几乎是即时的,因此您不需要将它放在后台线程中 - 您所做的只是浪费CPU时间和电池。 其次,它需要使用Context的Looper和消息队列,因此将它放在后台线程中是危险的恕我直言。 另请注意,您既绑定了服务又启动了服务。 在某些情况下这是合适的,但通常只需要一个或另一个。 Do NOT do a bindService() from doInBackground(). First, it is nearly instantaneous, so you d ... -
我最初接受了另一个答案,但似乎是错的。 .get()方法将阻止UI线程等待结果,并且还将阻止显示的任何对话框。 这是此方法的预期行为。 唯一的选择是不使用.get()如果后台活动是任何明显的时间,而是使用回调方法来调用活动。 I initially accepted the other answer but it seems to be wrong. The .get() method will block the UI thread to wait for the result and any dialo ...
-
ProgressDialog新的Activity Asynctask没有显示,为什么?(ProgressDialog new Activity Asynctask is not showing, why?)[2022-01-03]
您的对话框将在显示后立即被解除,因为您的doInBackground为空。 尝试添加Thread.sleep()几秒钟,只是为了模拟延迟。 此外,我怀疑你正在开始的新活动会让你的对话落后。 因此,我建议您暂时不使用这些新活动来测试代码。 public class RemoveDialog extends AsyncTask{ ProgressDialog asyncDialog; public RemoveDialog(Context c) { ... -
Android - progressdialog不会在AsyncTask中显示(Android - progressdialog not displaying in AsyncTask)[2023-08-18]
从return new HttpConnection(activity).execute().get(); 你基本上锁定你的UI线程。 一旦删除它应该工作,因为AsyncTasks应该工作。 目的是为了异步,所以boolean downloadData()应该有一个返回类型的void 。 如果您需要对数据做些什么,那么您应该实现一个接口“侦听器”并将其传递给AsyncTask。 听众示例: class TaskConnect extends AsyncTaskpublic class MainActivity extends Activity{ .. private Button btnLogin; .. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnLog ...相关文章
更多- Stack Overflow Architecture Update - Now At 95 Million Page Views A Month
- Becoming a data scientist
- Solr: a custom Search RequestHandler
- Drupal Forums instead of phpBB or vBulletin: A casestudy
- Scaling Pinterest - From 0 To 10s Of Billions Of Page Views A Month In Two Years
- struts1 怎么在action中获取页面post的参数
- Spring Data: a new perspective of data operations
- How to Start a Business in 10 Days
- Become a Master Designer: Rule Three: Contrast, Contrast, Contrast
- A Great List of Windows Tools
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)