简体   繁体   English

Ajax GET请求未在URL中显示参数

[英]Ajax GET request does not show parameters in the URL

I'm trying to do GET request onclick using jQuery AJAX function, but the problem is that I dont see the parameters in the URL: 我正在尝试使用jQuery AJAX函数执行GET请求onclick,但是问题是我没有在URL中看到参数:

Here is the code: 这是代码:

<a href="#" class="md-list-content" data-invoice-id=<?php echo $invoiceId; ?>  onclick="myFunction('<?php  echo $invoiceId;  ?>')">

Here the Javascript code: 这里是Javascript代码:

function myFunction(id) {
var invoice_detailsid = id;
//alert(id);
 $.ajax({
    url:"invoice_details", //the page containing php script
    type: "GET", //request type
    data: ({invoice_detailsid: invoice_detailsid}),
    success:function(data){
              console.log("success);
      }
   });
}

After I do submit, I want the URL to look like this: 提交后,我希望URL如下所示:

http://localhost/project/page_invoices/a0yO01t8ZUIAY

I need to do it this was without refreshing the page, and at the same time, I want to see the params when I do GET request. 我需要执行此操作,而无需刷新页面,同时,我想在执行GET请求时看到参数。

Please help! 请帮忙!

Thanks. 谢谢。

When making a ajax request the url of the current page is not changing. 发出ajax请求时,当前页面的URL不变。 The request it's not related to current page. 该请求与当前页面无关。 That's the advantage of ajax request that you stay in current page and you make a request in background. 这就是ajax请求的优点,即您留在当前页面中,并且在后台发出请求。

If you want to change the url of the current page without leaving it (or refresh) you will have to use history library from js. 如果要更改当前页面的URL而又不保留(或刷新)它,则必须使用js中的历史记录库。 Here you can find more information about history: https://developer.mozilla.org/en-US/docs/Web/API/History_API 在这里,您可以找到有关历史的更多信息: https : //developer.mozilla.org/en-US/docs/Web/API/History_API

data takes in a string and not an object. 数据采用字符串而不是对象。 Try something like this 试试这个

data: "paramName="+paramValue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM