私は単純な POST AJAX 呼び出しを持っています - これが完了したら、カスタム関数を実行したいです - 私は .success() を喜びもなく試しました - 誰かが私を助けてくれますか?
jQuery.post('http://www.site.com/product/123/', jQuery('#product_addtocart_form').serialize(), function()
// on success - do something here
});
私は単純な POST AJAX 呼び出しを持っています - これが完了したら、カスタム関数を実行したいです - 私は .success() を喜びもなく試しました - 誰かが私を助けてくれますか?
jQuery.post('http://www.site.com/product/123/', jQuery('#product_addtocart_form').serialize(), function()
// on success - do something here
});
$.ajax()の要件に基づいて、次のコールバックを使用できます。
.done(function() {
alert( "success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "complete" );
});
あなたはこれを行うことができます:
$.post(url, data, function () {
alert("success");
// Call the custom function here
myFunction();
});
またはこれ:
// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.post(url, data);
jqxhr.done(function () {
alert("second success");
// Call the custom function here
myFunction();
});
ajax 呼び出しでこれを試してください。
<script>
$.ajax({
type: "POST",
url: "./WebServices/MethodName",
data: "{someName: someValue}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var row = response.d;
if (row.length > 0) {
$.each(row, function (index, item) {
});
}
else {
$("#").html("No Rows Found");
}
},
failure: function () {
}
});
</script>
.ajaxの基本的な使い方は次のようになります。
HTML
<form id="foo">
<label for="bar">A bar</label>
<input id="bar" name="bar" type="text" value="" />
<input type="submit" value="Send" />
</form>
<!-- The result of the search will be rendered inside this div -->
<div id="result"></div>
JavaScript
/* Attach a submit handler to the form */
$("#foo").submit(function(event) {
/* Stop form from submitting normally */
event.preventDefault();
/* Clear result div*/
$("#result").html('');
/* Get some values from elements on the page: */
var values = $(this).serialize();
/* Send the data using post and put the results in a div */
$.ajax({
url: "test.php",
type: "post",
data: values,
success: function(){
alert("success");
$("#result").html('Submitted successfully');
},
error:function(){
alert("failure");
$("#result").html('There is error while submit');
}
});
});