Jump to content

Need Help on This urgently....


Mr.47

Recommended Posts

hi guys..im a new member nd m also new to ajax/php. iam trying to update my database through ajax technique. problem is dat parameters to update.php file are not passing. while alerting them in js file shows it correct. here is some code for better understanding..

 

<a onclick="updatedata(<?php echo $id; ?>)" href="#"><img src="images/save.png"></a>

 

update.js file:

 

// JavaScript Documentvar xmlhttp

function updatedata(id)

{

var xmlhttp

xmlhttp= GetXmlHttpObject()

if(xmlhttp==null)

{

alert("browser does not support HTTP request")

return

}

xmlhttp.onreadystatechange= function()

{

if(xmlhttp.readystate==4)

{

var updt= document.getElementById("mydata");

updt.value=xmlhttp.responseText;

}

}

var str= document.getElementById("mydata").value;

var url="insert.php?id=" + id + "&data=" + str;

xmlhttp.open("GET",url,true);

xmlhttp.send(null);

}

 

function GetXmlHttpObject()

{

if (window.XMLHttpRequest)

  {

  // code for IE7+, Firefox, Chrome, Opera, Safari

  return new XMLHttpRequest();

  }

if (window.ActiveXObject)

  {

  // code for IE6, IE5

  return new ActiveXObject("Microsoft.XMLHTTP");

  }

return null;

}

 

insert.php file:

 

<?php

$id=$_GET["id"];

$data=$_GET["data"];

$conn= mysql_connect("localhost", "root", "");

if(!$conn)

{

die("connection failed!" . mysql_error());

}

mysql_select_db("backend", $conn);

$query = "UPDATE  myfirst SET description ='$data' WHERE id='$id'";

mysql_query($query);

?>

 

kindly show me how can i pass the param id and the edited data(str) to the php update file?

 

Link to comment
Share on other sites

  • 2 weeks later...

As far as I can see, you are correctly passing the data to the insert.php, but as you may not wish to see the result, you have not coded a callback onreadystatechange. It may be useful to include a callback function where you can simply alert the responseText, so you can at least see what insert.php is outputting, and you could then add some debug output to insert.php to further help with debugging.  If you do not need the callback in the finished application, you could always remove it when you have it working.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.