The below is just a bit of my ajax code, at the moment my variable 'resp' is returning an entire response from test.php. Is there any way I can just return the responseText between a specified tag? ie. just get back the responseText of the html inside test.php's div of id="xyz"?
var loc="test.php?myinput=apple";
ajax.onreadystatechange=function() {
if (ajax.readyState==4 && ajax.status == 200) {
var resp = ajax.responseText;
}
}
ajax.open("GET",loc,true);
ajax.send(null);
What you need to do is pass a callback function to the somefunction as a parameter. This function will be called when the process is done working (ie, onComplete): somefunction: function(callback){ var result = ""; myAjax = new Ajax.
The jqXHR Object. The jQuery XMLHttpRequest (jqXHR) object returned by $. ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method.
The responseText method is used for all formats that are not based on XML. It returns an exact representation of the response as a string. Plain text, (X)HTML, and JSON are all formats that use responseText.
You could use jquery shorthand function load() to do this in a swift
$('#result').load('test.php' #container');
here result is the div where you want to place the response text and container is the your specified source element location of test.php
is this what you want?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With