Reputation: 161
Hi I am completely new to jQuery and also not the strongest with Javascript so I would appreciate some input on modifying this AJAX request to jQuery.
var test = new Array();
var bindThis = {
url: "sampleHandler.data",
method: "post",
}
mimetype: "text/json",
content: test
};
var request1 = dojo.io.bind(bindThis);
dojo.event.connect(request1, "load", this, "ResultsFunction");
My guest is this but I am not 100% sure I have the syntax correct.
var test = new Array();
var bindThis = {
url: "sampleHandler.data",
type: "post",
}
dataType: "text/json",
data: test
};
As for the dojo event handler I haven't been able to find a great resource on how to bind the request. My guest is something along these lines?
$(this).load(function(){"ResultsFunction"})
How am I making out? Thanks in advance.
EDIT: I forgot to add that this is an application that uses both Dojo and Prototype. I am trying to migrate the code to jQuery.
Upvotes: 0
Views: 652
Reputation: 2784
If you are going to perform a POST operation, most likely you want to send data that needs to be serialized to a JSON format (if your server operation is expecting that type of data), here's an example:
var dataToSend = {'taco':'yum'};
$.ajax({
url:'/myurl/',
dataType:'json',
contentType: 'application/json',
data: JSON.stringify(dataToSend),
type: 'POST',
success: function(data){
// perform operation with the data you receive
alert('success! received: ' + data);
}
});
You can get more info if you visit: api.jquery.com
Upvotes: 1
Reputation: 3345
From the jQuery AJAX API
$.ajax({
type: 'POST',
url: 'sampleHandler.data',
data: data,
dataType: 'json',
success: function (result)
{
}
});
Alternatively
$.post("sampleHandler.data", data,
function(result) {
},
"json"
);
Upvotes: 1