AJAX调用[object%20Object]而不是URL(Symfony)(AJAX calls [object%20Object] instead of URL (Symfony))
在小枝我使用
data-post-url="{{ path('ajax')}}"
所以我可以通过使用var path = $("#edit-url-js").data();
然而,不要去http://localhost/happysaucer/web/app_dev.php/ajax它到http://localhost/happysaucer/web/app_dev.php/profile/ [object%20Object]
这是奇怪的,因为当我console.log(路径)'路径'变量它返回正确的网址。 当我对url进行硬编码时,'path'变量返回ajax调用。
AJAX电话:
$(document).ready(function(){ var path = $("#edit-url-js").data(); $(".option-js").on("change", function() { $.ajax({ url: path, type: "post", data: "test", success: function(data) { } }); }); });
控制器操作
/** * @Route("/ajax", name="ajax") */ public function ajaxAction(Request $request) { $r = new JsonResponse(); return $r->setData([ 'success' => true, ]); }
枝条代码
<div class="consumeable-container" id="edit-url-js" data-post-url="{{ path('ajax')}}">
In twig I use
data-post-url="{{ path('ajax')}}"
so I can get the url in javascript by usingvar path = $("#edit-url-js").data();
However instead of going to http://localhost/happysaucer/web/app_dev.php/ajax it goes to http://localhost/happysaucer/web/app_dev.php/profile/[object%20Object]
Which is weird because when I console.log(path) the 'path' variable it return the right url. When I hardcode the url the 'path' variable returns the ajax call works like it should.
AJAX call:
$(document).ready(function(){ var path = $("#edit-url-js").data(); $(".option-js").on("change", function() { $.ajax({ url: path, type: "post", data: "test", success: function(data) { } }); }); });
Controller Action
/** * @Route("/ajax", name="ajax") */ public function ajaxAction(Request $request) { $r = new JsonResponse(); return $r->setData([ 'success' => true, ]); }
Twig code
<div class="consumeable-container" id="edit-url-js" data-post-url="{{ path('ajax')}}">
原文:https://stackoverflow.com/questions/50003024
最满意答案
从base / default目录复制purchaseorder.phtml文件,然后将其粘贴到当前模板中。 现在您可以在当前目录中更改purchaseorder.phtml的内容,它不会影响基本文件。如下所示,
复制自
应用程序/设计/前端/基/默认/模板/支付/表格/ purchaseorder.phtml
粘贴到
应用程序/设计/前端/基/ current_theme /模板/支付/表格/ purchaseorder.phtml
覆盖部分时,文件夹结构应类似于默认模板文件夹结构,如current_theme / template / form / payment / purchaseorder.phtml 。 抱歉英语不好。
Copy purchaseorder.phtml file from base/default directory then paste it in your current template. Now you can alter content of it purchaseorder.phtml in your current directory, it wont affect the base file.Like below,
Copy from
app/design/frontend/base/default/template/payment/form/purchaseorder.phtml
Paste to
app/design/frontend/base/current_theme/template/payment/form/purchaseorder.phtml
When you override a section, the folder structure should resemble the default template folder structure like current_theme/template/form/ payment/purchaseorder.phtml . sorry for bad english.
相关问答
更多-
您应该“告诉”您的布局要传递给内容的块。
... -
我将发布phtml和html文件的答案。 覆盖phtml文件 例如,如果你想覆盖site_name/vendor/magento/module-checkout/view/frontend/templates/cart/shipping.phtml ,你需要把它放在/site_name/app/design/frontend/ThemeName/default/Magento_Checkout/templates/cart/shipping.phtml 覆盖(KO)html文件 例如,如果你想覆盖/site ...
-
如何覆盖Magento中的联系我们页面(form.phtml)(How to override Contact Us Page (form.phtml) in Magento)[2023-07-21]
啊......我找到了答案。 我的包名是ultimo,我的默认主题是kokorugs。 正确的路径是app / design / frontend / ultimo / default / template / contacts / form.phtml Ahh... I have found my answer. My package name is ultimo and my default theme is kokorugs. The correct path was app/design/front ... -
从base / default目录复制purchaseorder.phtml文件,然后将其粘贴到当前模板中。 现在您可以在当前目录中更改purchaseorder.phtml的内容,它不会影响基本文件。如下所示, 复制自 应用程序/设计/前端/基/默认/模板/支付/表格/ purchaseorder.phtml 粘贴到 应用程序/设计/前端/基/ current_theme /模板/支付/表格/ purchaseorder.phtml 覆盖部分时,文件夹结构应类似于默认模板文件夹结构,如current_th ...
-
该部分的正确块类型是customer / address_edit。 所以请尝试以下方法: getLayout()->createBlock('customer/address_edit')->setTemplate('customer/address/edit.phtml')->toHtml(); echo $block; ?> The correct block type for that section is customer/address_ ...
-
您创建了该文件,但是您告诉Magento使用您的adminhtml主题吗? Magento在此处提供了相关文档: http : //www.magentocommerce.com/wiki/4_-_themes_and_template_customization/admin/using_custom_admin_theme_templates You created the file, but have you told Magento to use your adminhtml theme? Magen ...
-
从基础模板复制app/design/frontend/[VendorName]/[theme]/Magento_Tax/pricing/adjustment.phtml文件并将其放在app/design/frontend/[VendorName]/[theme]/Magento_Tax/pricing/adjustment.phtml 有关更多信息,请访问: http : //devdocs.magento.com/guides/v2.0/frontend-dev-guide/themes/theme-in ...
-
请转到您的主题并创建文件夹Magento_Sales / templates / email / items / order 然后下载default.phtml文件 来自/ vendor / magento / module-sales / view / frontend / templates / email / items / order 然后在这里粘贴Magento_Sales / templates / email / items /订购你的主题。 Please go to your theme a ...
-
只要XML块被正确放置,在phtml文件中你就应该能够将它带出来: getChildHtml('contactForm') ?> As long as the XML block is placed correctly, in a phtml file you should be able to bring it out with: getChildHtml('contactForm') ?>
-
使用checkout.onepage.payment作为参考而不是付款这将对您有所帮助 use checkout.onepage.payment as reference instead of payment this will help you