i want insert some of data in database by ajax call ($.ajax()) and generation tracking code by a code php and with others data it insert in database . how after (upon) insert in database, displaying to user it tracking code ? (Without Refresh Page)
With respect my code:
$('.insert').live('click',function(e){
e.preventDefault();
var dataObj = $(this).closest('form').serialize();
//alert(dataObj)
$.ajax({
type: "POST",
url: 'insert_customers',
data: dataObj,
cache: false,
success: function() {
//alert(idname)
$('.result').hide().fadeIn('slow').html("<div class='message'>Your information was successfully. your tracking code is : '+$tracking' </div>");
},
"error": function (x, y, z) {
// callback to run if an error occurs
alert("An error has occured:\n" + x + "\n" + y + "\n" + z);开发者_C百科
}
});
return false;
})
You can send back data to the client (either html or objects) and use the data in the success function. To do so you use whatever print method that your server language uses (ie. if php use echo, perl print, etc) To print a content header and the information (like you would on a normal request for a web page. I would sugesst sending a content header of Content-type:application/json
and format your data back as {"tracking":trackingVar}
Then in your success function define it as:
success: function(data) {
//alert(idname)
$('.result').hide().fadeIn('slow').html("<div class='message'>Your information was successfully. your tracking code is : " + data.tracking + " </div>");
},
精彩评论