简体   繁体   English

如何将参数传递给javascript中的URL?

[英]how to pass parameter to URL in javascript?

I need to pass the parameters to URL.I have posed the code. 我需要将参数传递给URL。我已经摆好了代码。

How can I pass the username and password entered in the textbox to URL in my code.thanks for any help.. 如何将在文本框中输入的usernamepassword传递给代码中的网址。感谢您的帮助。

You should not send password in the URL. 您不应在URL中发送password

If you want to pass some other details: Update these two lines as below: 如果要传递其他一些详细信息:如下更新这两行:

             data: {data1:$("input#data1").val(),data2:$("input#data2").val()},
             url: "http://localhost:53179/hdfcmobile/hdfc.ashx",

if you want to pass a url parameter, the you want to use: 如果要传递url参数,则要使用:

type: 'GET'

and also: 并且:

url: 'http://localhost:53179/hdfcmobile/hdfc.ashx

into the .ajax configs, using type:'POST' will post the fields into the headers instead of the url. 到.ajax配置中,使用类型:“ POST”会将字段发布到标头(而不是url)中。

Try below code: 试试下面的代码:

You can try your code in this pattern... 您可以按这种模式尝试代码...

var sdate = $('#banners_startdate').val();

var edate = $('#banners_enddate').val();

        if(sdate != '' && edate != ''){
            $.ajax({
                url: 'your url',
                data: 'apiname=get_banner_stat_platform_sharing&var=bannerstats&sdate=' + sdate + '&edate=' + edate,
                dataType: 'html',
                success: function(data){ 
                                         $('#bannerstats').html(data);
                                          return false;
                                       }
            });
        }

Where username and password can be fetch by id: 可以通过id获取用户名和密码的位置:

function ajaxcall(username,password)
   {
         jQuery.ajax({

                      type: "POST",

                      url: "Enter Url to pass",

                      data: {user: username, pass: password},

                      dataType: "html",

                      success: function(data) {
                          //write code what you want to do here
                      }

         });

   }

You can fetch the value on page by just $_POST['user'] and $_POST['pass'] . 您可以通过$_POST['user']$_POST['pass']来获取页面上的值。

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

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