ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Write an post method either in ajax or jquery which will work in all browser(old version and latest version)?

$.post( "submit.php", "username="+username+"&password="+password, function( data ) { alert(data); } In this case data are not posted in IE browser. var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("POST","demo_post2.asp",true); xmlhttp.setRequestHeader("Content-type","application/x-w-form-urlencoded"); xmlhttp.send("fname=Henry&lname=Ford"); This works fine with all browser except ie-10. I write code like below to support ie-10. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new ActiveXObject("Msxml2.XMLHTTP.6.0"); } It is not working with mozila, safari but working with ie-10. I have not checked with ie-7. It is a conflict.

user-image
تم إضافة السؤال من قبل Abhiram Giri
تاريخ النشر: 2013/10/16
Kaustav Banerjee
من قبل Kaustav Banerjee , Associate Software Engineer , AuricleSoft

The JQuery syntax is wrong

 

Try this

 

$.post(

"submit.php",

{username:username,password:password},

function( data ) { alert(data); }

); 

 

Also the variables that recieve these post data in submit.php must have same names as mentioned here (i.e username and password)

 

Look up this tutorial - http://a100websolutions.in/ajax-php-database-update/

Muhammad Majid Saleem
من قبل Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

You can learn it from following URLs:

  • http://api.jquery.com/jQuery.post/
  • http://api.jquery.com/jQuery.ajax/
  • http://www.w3schools.com/jquery/jquery_ref_ajax.asp
  • http://www.w3schools.com/jquery/ajax_ajax.asp

Mo'ath Al Mallahi
من قبل Mo'ath Al Mallahi , Senior PHP Developer , iHorizons

This could be done using jQuery like this:

$("#form_id").submit(function(){

$.ajax({

data: $(this).serialize(), //serialize the form data to be sent

url:'submit.php' //the target

type:'post' // method of the form wether get / post

success: function(dataFromBackEnd){

$(body).appened(dataFromBackEnd);

}

error: function(errorMsg){

alert(errorMsg);

}

});

return false;

});

Daanish Rumani
من قبل Daanish Rumani , Product Manager , Publicis Sapient

If you stick to jQuery then it handles all browser related worries. That is why jQuery was born in the first place.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟