如何在JavaScript中通过URL传递参数
我有一些数据表,我想从URL中获取参数id 194如何在JavaScript中通过URL传递参数,javascript,php,jquery,mysql,zend-framework,Javascript,Php,Jquery,Mysql,Zend Framework,我有一些数据表,我想从URL中获取参数id 194 admin/customer-management/updater/id/194 我的源AJAX: "sAjaxSource": "/<?= Zend_Registry::get('Zend_Locale')->getLanguage(); ?>/admin/CustomerManagement/getlistcontactsajax/idCustomer/" + $(this).attr('value'); “sAjax
admin/customer-management/updater/id/194
我的源AJAX:
"sAjaxSource": "/<?= Zend_Registry::get('Zend_Locale')->getLanguage(); ?>/admin/CustomerManagement/getlistcontactsajax/idCustomer/" + $(this).attr('value');
“sAjaxSource”:“//admin/CustomerManagement/getlistcontactsajax/idCustomer/”+$(this.attr('value');
我这样做
+$(this.attr('value')
但它不起作用。如果你有url变量,你可以使用regexurl.match(/\d+$/)
来获取它。如果你有url变量,你可以使用regexurl.match(/\d+$/)
来获取它。考虑到这个不清楚的问题,这就是我想到的
location.href
将为您提供当前页面的URL。在你的情况下(同样,我的假设),它是admin/customer management/updater/id/194
因此,请执行以下操作
var ID = location.href.split("/").pop();
上面创建了一个数组,如下所示,然后将数组中的最后一项分配给变量ID
["admin", "customer-management", "updater", "id", "194"]
然后,您可以执行以下操作:
"sAjaxSource": "/<?=Zend_Registry::get('Zend_Locale')->getLanguage();?>/admin/CustomerManagement/getlistcontactsajax/idCustomer/" + ID
“sAjaxSource”:“//admin/CustomerManagement/getlistcontactsajax/idCustomer/”+ID
考虑到问题的不明确性,我想到了这一点
location.href
将为您提供当前页面的URL。在你的情况下(同样,我的假设),它是admin/customer management/updater/id/194
因此,请执行以下操作
var ID = location.href.split("/").pop();
上面创建了一个数组,如下所示,然后将数组中的最后一项分配给变量ID
["admin", "customer-management", "updater", "id", "194"]
然后,您可以执行以下操作:
"sAjaxSource": "/<?=Zend_Registry::get('Zend_Locale')->getLanguage();?>/admin/CustomerManagement/getlistcontactsajax/idCustomer/" + ID
“sAjaxSource”:“//admin/CustomerManagement/getlistcontactsajax/idCustomer/”+ID
您可以通过以下方式实现:
parseInt(location.href.split("/").pop())
或
您可以通过以下方式实现此目的:
parseInt(location.href.split("/").pop())
或
显然,您使用PHP(与Zend一起)编写js代码。您可以使用以下方法恢复控制器中的id:
$id = $this->getRequest()->getParam('id');
因此,您可以使用它编写js代码(可能是视图中的pass变量):
“sAjaxSource”:“//admin/CustomerManagement/getlistcontactsajax/idCustomer/”,
显而易见,您使用PHP(与Zend一起)编写js代码。您可以使用以下方法恢复控制器中的id:
$id = $this->getRequest()->getParam('id');
因此,您可以使用它编写js代码(可能是视图中的pass变量):
“sAjaxSource”:“//admin/CustomerManagement/getlistcontactsajax/idCustomer/”,
是否要从URL获取id
?您需要重写您的问题。这是什么?i、 e.您访问attr(“value”)的哪个元素上的什么事件,在真实jQuery中可能是.val(),它与URL有什么关系?你的意思是location.href.split(“/”).pop()
“admin/customer management/updater/id/194”。split(“/”).pop()我想把这个参数添加到url ajaxsource中,以获取数据表是admin/customer management/updater/id/194
页面url的路径?或者您定义的变量?是否要从URL获取id
?您需要重写您的问题。这是什么?i、 e.您访问attr(“value”)的哪个元素上的什么事件,在真实jQuery中可能是.val(),它与URL有什么关系?你的意思是location.href.split(“/”).pop()
“admin/customer management/updater/id/194”。split(“/”).pop()我想把这个参数添加到url ajaxsource中,以获取数据表是admin/customer management/updater/id/194
页面url的路径?或者您定义的变量?看起来非常接近于我的建议,但没有回答,因为没有足够的信息来理解他的意思。看起来非常接近于我的建议,但没有回答,因为没有足够的信息来理解他的意思。为什么?它是一个用作stringWhy parseint的字符串?这是一个用作stringyes的字符串,但我在同一控制器中的其他函数中有参数updatercustom()如何从该函数执行请求,谢谢你,我不确定是否理解。如果updatercustom()生成id,在您的操作中,您可以执行$this->view->id=$this->updatercustom()
在您的视图中,您可以使用$this->id
参数,因此我在这个函数中有:公共函数updatecustomerAction(){$idCustomer=(int)$this->getRequest()->getParam('idCustomer');
但是我想在这个函数中获取参数`public function getlistcontactsajaxAction(){$contacts=new Admin\u Model\u DbTable\u Contact();$idCustomer=getparam在这里可以标识什么其他函数`感谢帮助您在哪里编写“sAjaxSource”:/Admin/CustomerManagement/getlistcontactsajax/idCustomer/“
?在updatecustomerAction
视图中?在getlistcontactsajaxAction
视图中?在updatecustomerAction视图中?因为我需要在updatecustomer视图中提前感谢是,但我在同一控制器的其他函数中有参数我如何从该函数UpdateCustom()执行请求,谢谢你,我不太清楚。如果UpdateCustom()生成id,在你的操作中,你可以做$this->view->id=$this->updatercustom();
,在你的视图中,你可以使用$this->id
参数,所以我在这个函数中有:公共函数updatecustomerAction(){$idCustomer=(int)$this->getRequest()->getParam('idCustomer');
但是我想在这个函数中获取参数`public function getlistcontactsajaxAction(){$contacts=new Admin\u Model\u DbTable\u Contact();$idCustomer=getParam可以在这里为其他函数标识什么`Thank for Help`您在哪里编写“sAjaxSource”:“//admin/CustomerManagement/getlistcontactsajax/idCustomer/”
?在updatecustomerAction
视图中?在getlistcontactsajaxAction
视图中?在updatecustomerAction视图中?因为我需要在updatecustomer视图中提前感谢