Rails:在内联js内部获得ruby内部的JS变量(Rails : get JS variable inside ruby inside inline js)
我需要根据用户点击的链接更改一些div内容。 这是我的代码
:javascript $('.some_clickable_item').on('click', function(e) { clicked_element_id=$(this).data("element_id") $('#my_destination_div').html("#{ render partial: "dashboard/some_partial_name", locals: {item_id: clicked_element_id} }"); })
显然,这是行不通的,因为clicked_element_id是一个js变量,但我需要将它传递给我的部分。
任何简单的想法,使其工作? 谢谢 !!
I need to change some div content depending on the link the user clicked. Here is my code
:javascript $('.some_clickable_item').on('click', function(e) { clicked_element_id=$(this).data("element_id") $('#my_destination_div').html("#{ render partial: "dashboard/some_partial_name", locals: {item_id: clicked_element_id} }"); })
Obviously, this is not working because clicked_element_id is a js variable, but i need to pass it to my partial.
Any simple idea to make it work ? Thanks !!
原文:https://stackoverflow.com/questions/41572260
更新时间:2019-10-08 21:43
最满意答案
问题可能是内容类型中的分号:
fileentity = new FileEntity(file,"image/jpeg;"); ^
The problem may be the semicolon in the content type:
fileentity = new FileEntity(file,"image/jpeg;"); ^
相关问答
更多-
尝试使用标准参数创建DefaultHTTPClient。 HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpClient httpClient = new DefaultHttpClient(params); 它对我来说很好。 我还使用UTF-8编码设置请求实体: httppost.set ...
-
假设您有一个Login操作,为用户提供一个登录屏幕,然后在用户提交表单后再次收到用户名和密码: public ActionResult Login() { return View(); } public ActionResult Login(string userName, string password) { // do login stuff return View(); } 即使我们可以通过查看,MVC也没有给出明确的指示,哪个动作是哪个。 如果您将[HttpGet]添加到 ...
-
尝试在您的响应中使用EntityUtil : String responseBody = EntityUtils.toString(response.getEntity()); Try to use the EntityUtil on your response: String responseBody = EntityUtils.toString(response.getEntity());
-
Android使用Apache的HTTPClient 。 所以,复制他们的教程代码 : public void sendStringTo(String remoteUrl, String myString) { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(remoteUrl+"?string1="+myString); HttpResponse respon ...
-
目前你没有发送任何东西。 HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.yoursite.com/"); try { // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); HttpEntit ...
-
问题可能是内容类型中的分号: fileentity = new FileEntity(file,"image/jpeg;"); ^ The problem may be the semicolon in the content type: fileentity = new FileEntity(file,"image/jpeg;"); ...
-
您问:我不是将“QueryStringParameters”添加到客户端并将其用作第二个参数吗? 答案是:是的 说明 WebClient类的QueryString属性用于构建作为查询字符串附加到WebClient URI的名称/值对,因此主要用于Get请求。 假设你想要,你仍然可以这样做: byte[] ResponseBytes = client.UploadValues(URL, client.QueryString); 但这显然是浪费,因为你也可以直接传递它。 You asked: Do I not ...
-
我的理解是,默认情况下它接受无论是GET还是POST两种类型的请求。 但是当一个动作方法用[httpGet]或[httpPost]属性修饰时,action方法只接受那些由属性定义的请求方法。 What I understand, By default It accept both type of request whether it is GET or POST. but when a action method is decorated with either [httpGet] or [httpPost ...
-
错误信息很明确...... ...如果您知道可选参数是具有默认值的参数(在您的情况下为空字符串) [HttpPost] public ActionResult Edit(EditViewModel viewModel, string itemId="") { // ... RedirectToAction("Edit", new { id = itemId }); } 你已经完成了 Error message is clear... ... if you know that an opt ...
-
在这里你可以将post参数附加到url,然后进行调用就可以了 `HttpGet _getrequest=new HttpGet("http://aleedex.biz/game/users.php? action=new&"+postParameter); HttpResponse httpResponse = httpClient.execute(_getrequest); HttpEntity httpEntity = httpResponse.getEntity(); json ...