I am new to symfony. I have created a twig file named as index.html.twig
. In this I have written a code for making an ajax request as follow:
<script language="javascript">
function onsub()
{
alert(document.getElementById('source').value);
var http=new XMLHttpRequest();
var name="rohit";
if(http.open("POST", "sub.html.php?field="+name, true)) alert('yes');
alert(http);
http.onreadystatechange = function()
{
if(http.readyState == 4 && http.status == 200)
{
alert('i m back');
}
else
{
alert('sorry');
}
}
http.send();
}
</script>
This is the action called when I press the submit button to submit a form. when I submit the form, this action is called and the correct value is poped out but it is not sending the data to requested file ie sub.html.php
. it is making the object correctly. and when I am printing the value of http.readyState
then it is giving the answer as 1
. so I want to send the value of name
to the requested file sub.html.php
. what can I do for this?
try this .....
<script language="javascript">
function onsub()
{
var name="rohit";
alert(document.getElementById('source').value);
if(window.XMLHttpRequest)
{
http=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
http=new ActiveXObject("Microsoft.XMLHTTP");
}
http.onreadystatechange=function()
{
if(http.readyState == 4 && http.status == 200)
{
alert('i m back');
}
else
{
alert('sorry');
}
}
http.open("GET", "sub.php?field="+name , true);
http.send();
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.