Reputation: 11793
All , forgive me I am a newbie of jquery .I found there doesn't exist more detail of this api in jquery load api. Here is what I had lean from it and I have some the question about it.please review it.
This api include these ways of usage to make a ajax call.
$('#result').load('ajax/test.html');
//ajax load a html file , it use
Get
method.$('#result').load('ajax/test.html .someclass');
//ajax load the
selected content from a html file.$('#result').load('ajax/test.html', function() { alert('Load was
performed.');});
//call back when it succeed. $(document).ready(function(){ $("input").keyup(function(){
txt=$("input").val();
$("span").load("/jquery/gethint.asp",{suggest:txt}); }); });
//I am not sure what is this data
mean. How the server side get this data
?So far , I didn't find the example when data is a string which will add in the url as parameters by jquery. I hope someone also can illustrate some code for me . thanks.
Updated
Please note the load
api always be with the serialize
method to format the UI input values to json. thanks.
Upvotes: 1
Views: 623
Reputation: 167172
The data
in jQuery $.load()
can be given in these ways.
As a JSON object.
data: {"foo": "bar"}
As a string
data: "foo=bar"
You can use both the ways. The first one is the object way.
For your four queries:
GET
method.data
is explained above.PHP
<?php
if (!isset($_GET['foo']) && $_GET['foo'] == "bar")
die("true");
else
die("false");
?>
ASP
<%
IF Request.Form("foo") = "bar" Then
Response.Write "true"
ELSE
Response.Write "false"
END IF
%>
Upvotes: 2
Reputation: 4092
there are different ways to use Ajax in jQuery, with the basic one being .ajax().
Here are some useful shorthand methods: http://api.jquery.com/category/ajax/shorthand-methods/
These methods do the same as ajax, only with easier syntax and preconfigured to do specific tasks.
I'm not sure i understood your question, but i'll answer for any interpertation of your question:
if you want to send a parameter to the server, you use the second parameter of the load function to send a parameter, as such:
$('#result').load('ajax/test.html', {prop:val, prop2:val});
these props will be added to your request (either by get or by post methods, as per configuration)
if you wish to recieve the data from the server into a parameter, you use the following:
$('#result').load('ajax/test.html', function(data){ console.log(data); });
in this case, function is a callback that runs once the request is complete, and data holds all of the contents of the response from the server.
Upvotes: 1