Let’s say I want to execute a PHP script. Which way is better?
This:
$.ajax({
type: "GET",
url: "php-script.php",
dataType: "script"
});
Or this:
$.get("php-script.php", function(data) { });
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In this case, I’d say
$.get, as it’s immediately clear what the type of request is. At any rate, it’s just shorthand for the larger and more option-ified ajax call, and converting between the two is trivial in the worst case.If you think that you’ll need fancy
$.ajaxoptions, use$.ajax. If you don’t use the convenience methods jQuery provides, such as.load,$.get, etc.