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 <tcolo...@gmail.com> 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 <shanerileydoti...@gmail.com> 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. > > > <?php > > $header2 = '<div id="header2"><p>Some text in header2 ...</p></div>'; > > if ($_GET[ajax]) > > { ?> > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> > > <html> > > <head> > > <title>Test file</title> > > <meta http-equiv="Content-Type" content="text/html; > > charset=windows-1251"> > > </head> > > <body> > > <div id="header"><p>Some text in div header</p></div> > > <? > > $id = isset($_GET["ID"]) ? $_GET["ID"] : ""; > > $number = isset($_GET["NUMBER"]) ? $_GET["LOT_NUMBER"] : ""; > > echo "<p><b>id =</b>" . $id . "</p>"; > > echo "<p>number = " . $number . "</p>"; > > echo $header2; > > ?> > > </body> > > </html> > > <?php } else { echo $header2; } ?> > > > However ideally you'd use a separate PHP function or file altogether > > to handle it. > > > On Apr 22, 8:21 pm, Colonel <tcolo...@gmail.com> wrote: > > > > I know it. But how I can get content from remote file by $.ajax? > > > For example I have some file temp.php: > > > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> > > > <html> > > > <head> > > > <title>Test file</title> > > > <meta http-equiv="Content-Type" content="text/html; > > > charset=windows-1251"> > > > </head> > > > <body> > > > <div id="header"><p>Some text in div header</p></div> > > > <? > > > $id = isset($_GET["ID"]) ? $_GET["ID"] : ""; > > > $number = isset($_GET["NUMBER"]) ? $_GET["LOT_NUMBER"] : ""; > > > echo "<p><b>id =</b>" . $id . "</p>"; > > > echo "<p>number = " . $number . "</p>"; > > > ?> > > > <div id="header2"><p>Some text in header2 ...</p></div> > > > </body> > > > </html> > > > > 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 <shanerileydoti...@gmail.com> 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 <tcolo...@gmail.com> wrote: > > > > > > Is there another way load HTML from a remote file and inject it into > > > > > the DOM (instead of $.load)?