Click here to Skip to main content
Sign Up to vote bad
good
See more: AjaxjQuery
I have generated a website:
 
http://www.mysite/page.aspx?var1="123"&var2="456"
 
I am looking to extract var1 and var2 with an Ajax and jQuery program using the GET method.
 
I am using jQuery:
 
<script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
 
I got a part of a Program;
 
<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $.ajaxSetup({
            cache: false,
            dataType: "html",
            error: function(xhr, status, error) {
                alert('An error occurred: ' + error);
            },
            timeout: 30000,
            type: "GET",
            beforeSend: function() {
                console.log('In Ajax beforeSend function');
            },
            complete: function() {
                console.log('In Ajax complete function');
            }
        });
        //I want to extract var1 and var2 into textboxes
    });
</script>
 
Any help would be appreciated.
Posted 21 Feb '13 - 6:53


1 solution

No, your var1 and var2 and their values are not part of HTTP request data, they are the part of request URI itself. So, take the current URI window.location and extract the parameters.
 
[EDIT]
 
You will find enough code samples doing it, such as:
http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery[^],
http://stackoverflow.com/questions/1280557/extract-parameter-value-from-url-using-regular-expressions[^].
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 523
1 Mahesh Bailwal 393
2 Maciej Los 205
3 Aarti Meswania 200
4 Tadit Dash 145
0 Sergey Alexandrovich Kryukov 9,607
1 OriginalGriff 7,214
2 CPallini 3,943
3 Rohan Leuva 3,261
4 Maciej Los 2,758


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid