[jQuery] Re: Alternate $.load
It would be much easier to generate a json response instead of html and use .getJSON and then the DOM insertion functions to generate the html you need on the page. On Apr 23, 1:41 am, Colonel wrote: > This isn't entirely correct, and not quite what I had. For example I > have a lots of divs in temp.php (after work with DB). And in the end > of $.ajax I have msg. How I can manipulate with this and find divs and > p and so on ? > > On 23 апр, 05:08, Shane Riley wrote: > > > Typically you'd only echo the data back that you want instead of > > having to weed through a string of HTML data to extract what you need. > > From what it looks like, you're needing a specific element from > > another page while still being able to access the other page > > (temp.php) in its entirety. The easiest solution in this case would be > > to send some data to temp.php letting it know that you're initializing > > an asynchronous request, and then have the PHP return only what you're > > looking for. A quick solution in this case would be something like > > this: > > > $.ajax({url: 'temp.php', > > data: "ajax=true", > > cache: false, > > error: function(msg) {alert("Error Saved: " + msg);}, > > success: function(msg) {alert("Data Saved: " + msg);}, > > complete: function() {$.unblockUI();} > > }); > > Then in temp.php, check for this flag, and if it's true, send the > > header2 div only. > > > > $header2 = 'Some text in header2 ...'; > > if ($_GET[ajax]) > > { ?> > > > > > > > > Test file > > > > > > > > Some text in div header > > > $id = isset($_GET["ID"]) ? $_GET["ID"] : ""; > > $number = isset($_GET["NUMBER"]) ? $_GET["LOT_NUMBER"] : ""; > > echo "id =" . $id . ""; > > echo "number = " . $number . ""; > > echo $header2; > > ?> > > > > > > > > > However ideally you'd use a separate PHP function or file altogether > > to handle it. > > > On Apr 22, 8:21 pm, Colonel wrote: > > > > I know it. But how I can get content from remote file by $.ajax? > > > For example I have some file temp.php: > > > > > > > > > > > > > Test file > > > > > > > > > > > > Some text in div header > > > > > $id = isset($_GET["ID"]) ? $_GET["ID"] : ""; > > > $number = isset($_GET["NUMBER"]) ? $_GET["LOT_NUMBER"] : ""; > > > echo "id =" . $id . ""; > > > echo "number = " . $number . ""; > > > ?> > > > Some text in header2 ... > > > > > > > > > > and Am using $.ajax: > > > > $.ajax({url: 'temp.php', > > > cache: false, > > > error: function(msg) {alert("Error Saved: " + msg);}, > > > success: function(msg) {alert("Data Saved: " + msg);}, > > > complete: function() {$.unblockUI();} > > > }); > > > > how I can get for example content only from div with id=header2 ? > > > > On 23 апр, 01:55, Shane Riley wrote: > > > > > You can use a number of Ajax functions built in to JQuery depending on > > > > your specific needs. Check them out athttp://docs.jquery.com/Ajax. If > > > > all you're looking to do is insert one file into another, load is > > > > normally the way to go, unless you're looking to place the loaded file > > > > before, after, or in between elements rather than inside a placeholder > > > > element. > > > > > On Apr 22, 5:50 pm, Colonel wrote: > > > > > > Is there another way load HTML from a remote file and inject it into > > > > > the DOM (instead of $.load)?
[jQuery] Re: Alternate $.load
This isn't entirely correct, and not quite what I had. For example I have a lots of divs in temp.php (after work with DB). And in the end of $.ajax I have msg. How I can manipulate with this and find divs and p and so on ? On 23 апр, 05:08, Shane Riley wrote: > Typically you'd only echo the data back that you want instead of > having to weed through a string of HTML data to extract what you need. > From what it looks like, you're needing a specific element from > another page while still being able to access the other page > (temp.php) in its entirety. The easiest solution in this case would be > to send some data to temp.php letting it know that you're initializing > an asynchronous request, and then have the PHP return only what you're > looking for. A quick solution in this case would be something like > this: > > $.ajax({url: 'temp.php', > data: "ajax=true", > cache: false, > error: function(msg) {alert("Error Saved: " + msg);}, > success: function(msg) {alert("Data Saved: " + msg);}, > complete: function() {$.unblockUI();} > }); > Then in temp.php, check for this flag, and if it's true, send the > header2 div only. > > $header2 = 'Some text in header2 ...'; > if ($_GET[ajax]) > { ?> > > > > Test file > > > > Some text in div header > $id = isset($_GET["ID"]) ? $_GET["ID"] : ""; > $number = isset($_GET["NUMBER"]) ? $_GET["LOT_NUMBER"] : ""; > echo "id =" . $id . ""; > echo "number = " . $number . ""; > echo $header2; > ?> > > > > > However ideally you'd use a separate PHP function or file altogether > to handle it. > > On Apr 22, 8:21 pm, Colonel wrote: > > > I know it. But how I can get content from remote file by $.ajax? > > For example I have some file temp.php: > > > > > > > > > Test file > > > > > > > > Some text in div header > > > $id = isset($_GET["ID"]) ? $_GET["ID"] : ""; > > $number = isset($_GET["NUMBER"]) ? $_GET["LOT_NUMBER"] : ""; > > echo "id =" . $id . ""; > > echo "number = " . $number . ""; > > ?> > > Some text in header2 ... > > > > > > > and Am using $.ajax: > > > $.ajax({url: 'temp.php', > > cache: false, > > error: function(msg) {alert("Error Saved: " + msg);}, > > success: function(msg) {alert("Data Saved: " + msg);}, > > complete: function() {$.unblockUI();} > > }); > > > how I can get for example content only from div with id=header2 ? > > > On 23 апр, 01:55, Shane Riley wrote: > > > > You can use a number of Ajax functions built in to JQuery depending on > > > your specific needs. Check them out athttp://docs.jquery.com/Ajax. If > > > all you're looking to do is insert one file into another, load is > > > normally the way to go, unless you're looking to place the loaded file > > > before, after, or in between elements rather than inside a placeholder > > > element. > > > > On Apr 22, 5:50 pm, Colonel wrote: > > > > > Is there another way load HTML from a remote file and inject it into > > > > the DOM (instead of $.load)?
[jQuery] Re: Alternate $.load
Typically you'd only echo the data back that you want instead of having to weed through a string of HTML data to extract what you need. >From what it looks like, you're needing a specific element from another page while still being able to access the other page (temp.php) in its entirety. The easiest solution in this case would be to send some data to temp.php letting it know that you're initializing an asynchronous request, and then have the PHP return only what you're looking for. A quick solution in this case would be something like this: $.ajax({url: 'temp.php', data: "ajax=true", cache: false, error: function(msg) {alert("Error Saved: " + msg);}, success: function(msg) {alert("Data Saved: " + msg);}, complete: function() {$.unblockUI();} }); Then in temp.php, check for this flag, and if it's true, send the header2 div only. Some text in header2 ...'; if ($_GET[ajax]) { ?> Test file Some text in div header id =" . $id . ""; echo "number = " . $number . ""; echo $header2; ?> However ideally you'd use a separate PHP function or file altogether to handle it. On Apr 22, 8:21 pm, Colonel wrote: > I know it. But how I can get content from remote file by $.ajax? > For example I have some file temp.php: > > > > > Test file > > > > Some text in div header > $id = isset($_GET["ID"]) ? $_GET["ID"] : ""; > $number = isset($_GET["NUMBER"]) ? $_GET["LOT_NUMBER"] : ""; > echo "id =" . $id . ""; > echo "number = " . $number . ""; > ?> > Some text in header2 ... > > > > and Am using $.ajax: > > $.ajax({url: 'temp.php', > cache: false, > error: function(msg) {alert("Error Saved: " + msg);}, > success: function(msg) {alert("Data Saved: " + msg);}, > complete: function() {$.unblockUI();} > }); > > how I can get for example content only from div with id=header2 ? > > On 23 апр, 01:55, Shane Riley wrote: > > > You can use a number of Ajax functions built in to JQuery depending on > > your specific needs. Check them out athttp://docs.jquery.com/Ajax. If > > all you're looking to do is insert one file into another, load is > > normally the way to go, unless you're looking to place the loaded file > > before, after, or in between elements rather than inside a placeholder > > element. > > > On Apr 22, 5:50 pm, Colonel wrote: > > > > Is there another way load HTML from a remote file and inject it into > > > the DOM (instead of $.load)?
[jQuery] Re: Alternate $.load
I know it. But how I can get content from remote file by $.ajax? For example I have some file temp.php: Test file Some text in div header id =" . $id . ""; echo "number = " . $number . ""; ?> Some text in header2 ... and Am using $.ajax: $.ajax({url: 'temp.php', cache: false, error: function(msg) {alert("Error Saved: " + msg);}, success: function(msg) {alert("Data Saved: " + msg);}, complete: function() {$.unblockUI();} }); how I can get for example content only from div with id=header2 ? On 23 апр, 01:55, Shane Riley wrote: > You can use a number of Ajax functions built in to JQuery depending on > your specific needs. Check them out athttp://docs.jquery.com/Ajax. If > all you're looking to do is insert one file into another, load is > normally the way to go, unless you're looking to place the loaded file > before, after, or in between elements rather than inside a placeholder > element. > > On Apr 22, 5:50 pm, Colonel wrote: > > > Is there another way load HTML from a remote file and inject it into > > the DOM (instead of $.load)?
[jQuery] Re: Alternate $.load
You can use a number of Ajax functions built in to JQuery depending on your specific needs. Check them out at http://docs.jquery.com/Ajax. If all you're looking to do is insert one file into another, load is normally the way to go, unless you're looking to place the loaded file before, after, or in between elements rather than inside a placeholder element. On Apr 22, 5:50 pm, Colonel wrote: > Is there another way load HTML from a remote file and inject it into > the DOM (instead of $.load)?