user751828
user751828

Reputation: 85

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

Upvotes: 1

Views: 2646

Answers (4)

Varun Bansal
Varun Bansal

Reputation: 382

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

Upvotes: 0

Yogendra Singh
Yogendra Singh

Reputation: 34367

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",

Upvotes: 1

harsh4u
harsh4u

Reputation: 2600

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;
                                       }
            });
        }

Upvotes: 0

RicardoE
RicardoE

Reputation: 1725

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.

Upvotes: 0

Related Questions