简体   繁体   中英

how to pass parameter to URL in javascript?

I need to pass the parameters to URL.I have posed the code.

How can I pass the username and password entered in the textbox to URL in my code.thanks for any help..

You should not send password in the URL.

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:

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.

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:

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'] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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