Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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
Question ajoutée par Abhiram Giri
Date de publication: 2013/10/16
Fadi Alkhateeb
par Fadi Alkhateeb , Senior Front End Developer , NexTwo

I think using Jquery will be just fine and support all browsers including IE6:

http://www.w3schools.com/jquery/jquery_ajax_get_post.asp

http://www.w3schools.com/jquery/jquery_ref_ajax.asp

Kaustav Banerjee
par 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
par 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
par 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
par 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.

More Questions Like This