I am having a problem using the XMLHTTPRequest, is something wrong in my code? How do you post data, I tried this but the PHP does not receibe any posted information, like if nothing was sended, i try this with Firefox 1.0.6 on Linux Fedora Core 3, thanks in advance for any ideas...., could it be some kind of firefox implementation bug? Code:
I have a form in a webpage that I want to submit and get the result back without reloading the page.
I've seen many times ppl using text/x-www-form-urlencode but I was wondering if it was possible somehow to submit the form element directly so I wouldn't have to process the form to put it in a string.
My JavaScript is trying to POST data to a CGI script (Perl) using XMLHttpRequest. My CGI server gets different data from IE than Mozilla Firefox.
// For Mozilla, req = new XMLHttpRequest(); // For IE req = new ActiveXObject("Microsoft.XMLHTTP"); req.onreadystatechange = requestHandler ; // function to handle async response req.open('POST', myURL, true); // use POST req.send('foo=11&bar=22') ;
A Perl CGI script prints the parameters passed to it. $q = new CGI ; foreach my $param ($q->param) { print "$param: " . $q->param($param) . " " ; }
The data received by the CGI script is inconsistent, depending if the client is IE or Mozilla (Firefox) Server result from IE client: foo: 11 bar: 22 Server result from Mozilla Firefox client: POSTDATA: foo=11&bar=22
It seems that the POST data IE sends is more correct than the Mozilla data. Is there another way to send the data in Mozilla so the CGI script will give the same results. I could easily adjust the CGI script, but I think the problem is at the client.
The following script works fine in IE6. In FF 1.0.7, it doesn't display the response text. The alert()'s in the script show that:
1) the script successfully creates the request object 2) 'http_request.status' starts off equal to 0 3) the readystate displays: 1, 1, 2, 4 4) an error occurs when the script tries to access the .status property of the request object after the request has been sent and the readyState reaches 4(line marked in red below).
<html> <head><title></title> <script type="text/javascript" language="javascript"> function makeRequest(url) { var http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); alert(http_request); //object XMLHttpRequest alert("status: " + http_request.status); //status: 0 /* alert("overriding mime type"); http_request.overrideMimeType('text/xml'); */ } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } http_request.onreadystatechange = function() { alertContents(http_request); }; http_request.open('GET', url, true); http_request.send(null); }
function alertContents(http_request) { alert(http_request.readyState); if (http_request.readyState == 4) {
ERROR ---> if(http_request.status) alert("status property exists"); else alert("no status property");
if (http_request.status == "200") { alert(http_request.responseText); } else { alert('There was a problem with the request.'); } } } </script> </head> <body> <div><a href="" onclick="makeRequest('someText.txt')">click me</a></div> </body> </html>
document.onclick=handler; function handler(e) { //do stuff var params = "something"; var request = new XMLHttpRequest(); request.open("GET", "http://www.foo.com/bar.php?" + params, true); [Code]....
Now is user clicks something else but not a link everything works just fine. But if she clicks a link, the bar.php call does not work (never comes to the server). If I change the call to a synchronuous one request.open("GET", [URL] false) also clicking a link works fine. But I would of course prefer the async way.
The post is submitted and returns correctly (confirmed by firebug lite), however the code inside the nested function fails to execute on both IE6 and IE7. Works fine on IE8, everything else. $ ( "form.add" ). submit ( function () { //code outside of .post function executes successfully $ .post .....
doing the same through the html form-element works, what could the problem be?
my error function returns 0 for the xhr.status, error for the textStatus and undefined for the errorThrown.EDIT: i just tried the http_post_field function of the php pecl library. this works aswell. could it be that my data string is not correct?
I have a small code which needs to authenticate against a service and return me the key. Following is the code, which works fine in IE8, the same is not working in Firefox(getting empty response).
if (window.XMLHttpRequest) { http=new XMLHttpRequest(); }
I tried the same code without apostrophes, but with no effect.
[Code]...
I found error... In POST variables passed to ajax.php I had 'content': content and content is probably jQuery reserved word (and this variable wasn´t define before). But I don´t know why that works in FF.
I have an error when I POST to a page. Whatever monetary choice of donation that is made, the POST does not work to send the values to the next page and the default value of $20.00 is registered.
After looking at my code for a day I dont see the errorL
Here is the code
Contributions are tax deductible for residents of the United States and Jamaica.
Yes, I want to become a contributor. Please accept my donation as indicated below.
[/code]
Here is the test site. [url]
For this test all menu choices takes to the Donation page.
I can get it works if I using <form> tag with an action="post" and a submit button to post to another php page by using this statement to get all controls in receiver's page _GET['mycheckbox'];I have tried
I just started using jQuery, but i can't get it working. On the index.php page I want a search form, that post's to search.php. Following next, I want that the html of search.php (which will only be a table with the results), is show into the 'results' div in the index.php.
This is the code im using:
<script type="text/javascript"> /* attach a submit handler to the form */ $(document).ready(function(){ alert("Ok - 1");
[Code].....
The alert's are for debugging, but none of them show's up.
Yesterday I started rewriting the xmlhttprequest functions to an oo equivalent, but as it turns out, I don't get it right:
Code:
function Request() { this.req=init(); this.req.onreadystatechange = this.processedRequest; //addEventHandler/attachEvent alternative //doesn't work either
function init() { try { if(window.XMLHttpRequest) return new XMLHttpRequest(); else return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert(e); } } }
var x=new Request(); x.send(url); //the processing function //the eventtrigger should activate the callback function //when the xml has been returned
It seems like the problem is that I don't get to my "this.req" in the processedRequest function. Can anyone see where the problem lies, it has been turning me crazy all weekend already.
1. - I am new to this 2. - Using the following .js file:
Code: function makeObject(){ var x; if (window.ActiveXObject) { x = new ActiveXObject("Microsoft.XMLHTTP"); }else if (window.XMLHttpRequest) { x = new XMLHttpRequest(); } [Code]...
Ive been playing around with xmlHTTPRequest and was wondering if i was programming a part of my code wrong.
what i want to do is have the browser access another part of my site using xmlhttprequest.
however, when i use xmlhttp.open("POST", 'http://xml.mysite.com/test.php') it fails, but if i use xmlhttp.open("POST", 'http://www.mysite.com/test.php') it works. Is access to another url restricted in xmlhttp?