开发者

how to use xmlhttprequest object's post method for sending data

I want to send data that is in a java script variable to the server.the variable is in a method that is executing when I click a button on the web site.here is the code written in that method for sending data.

    var xmlhtt开发者_如何学Gop;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("POST","new_map.php",true);
xmlhttp.send(cur_entry_string);

and here is code written in new_map.php file for getting data.here cur_entry_string is the variable that is holding that data.

$massage = $_POST[cur_entry_string];

but this is not working..:(...I am using eclipse.


Maybe you should have a look at an AJAX tutorial http://www.w3schools.com/ajax/default.asp and if that is not what you want to do you can also look into JSON


You need to actually generate a valid query string. A query string in POST looks the same as a GET string.

Something like this should work:

xmlhttp.send('cur_entry_string=' + cur_entry_string);

I would recommend using a library such as jQuery for using Ajax, as it simplifies the process a lot so you don't need to do error prone things like these query string things yourself.


ps. note that you should enclose array string indices in quotes when using PHP:

$_POST['cur_entry_string']
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜