8

this is a general-purpose way to make GET requests with jQuery:

var loadUrl="mypage.php";
$("#get").click(function(){   
    $("#result").html(ajax_load);   
    $.get(   
        loadUrl,   
        {language: "php", version: 5},   
        function(responseText){   
            $("#result").html(responseText);   
        },   
        "html"  
    );   
});  

I was wondering if I could pass parameters (Ex.language and version) directly in the URL(after urlencoding them):

var loadUrl="mypage.php?language=php&version=5";
$("#get").click(function(){   
    $("#result").html(ajax_load);   
    $.get(   
        loadUrl,      
        function(responseText){   
            $("#result").html(responseText);   
        },   
        "html"  
    );   
});  

Is that possible? And anyhow which is the cleanest solution to make an ajax call if I have all of the parameters I need urlencoded (Ex.<a href="mypage.php?language=php&version=5">rate me</a>)

1
  • 7
    Have you tried it? The answer is, yes, it will work, but its not the most elegant solution. Commented Mar 21, 2011 at 20:35

2 Answers 2

24

Yes that is possible but you can also do it this way.

$.get(
   "mypage.php", 
   { version: "5", language: "php" }, // put your parameters here
   function(responseText){
      console.log(responseText);
   },
   'html'
);
Sign up to request clarification or add additional context in comments.

Comments

4
$.get(

  url: url,    //your url eg. mypage.php

  data: data,   // Parameter you want to pass eg. {version:"5" , language : "php"}

  success: callback // function after success

);

follow the below link

http://api.jquery.com/jQuery.getJSON/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.