Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.ajax ( {
- type: 'POST',
- url: '<?=$_SERVER['PHP_SELF']?>',
- dataType: 'json',
- data: {step:''}
- }
- ).done(
- function(infj) {
- $.each(infj, function(i,valu) {
- var zDiv=$('<div>',{'class':'img_div'});
- var zImg=$('<img>',{'src':valu['small'],'rel':valu['big']});
- //--------------------------------
- zDiv.append(zImg);
- $('#allpics').find('#zclose').before(zDiv);
- });
- //----------------------------------------------------------------------------------------------
- $.ajax ( {
- type: 'POST',
- url: '<?=$_SERVER['PHP_SELF']?>',
- data: {step:'', favpic:inpic}
- }).done(
- function(html) {
- //alert(html);
- });
- //----------------------------------------------------------------------------------------------
- $.ajax({
- url: "test.html",
- context: document.body
- }).done(function() {
- $(this).addClass("done");
- });
- //--------------------------------------------
- $.ajax({
- statusCode: {
- 404: function() {
- alert("page not found");
- }
- }
- });
- //--------------------------------------------
- $.ajax({
- url: a_cross_domain_url,
- xhrFields: {
- withCredentials: true
- }
- });
- //--------------------------------------------
- $.ajax({
- url: "http://fiddle.jshell.net/favicon.png",
- beforeSend: function ( xhr ) {
- xhr.overrideMimeType("text/plain; charset=x-user-defined");
- }
- }).done(function ( data ) {
- if( console && console.log ) {
- console.log("Sample of data:", data.slice(0, 100));
- }
- });
- //--------------------------------------------
- var jqxhr = $.ajax( "example.php" )
- .done(function() { alert("success"); })
- .fail(function() { alert("error"); })
- .always(function() { alert("complete"); });
- // perform other work here ...
- // Set another completion function for the request above
- jqxhr.always(function() { alert("second complete"); });
- //--------------------------------------------
- $.ajax({
- url: 'ajax/test.html',
- success: function(data) {
- $('.result').html(data);
- alert('Load was performed.');
- }
- });
- //--------------------------------------------
- var _super = jQuery.ajaxSettings.xhr;
- jQuery.ajaxSettings.xhr = function () {
- var xhr = _super(),
- getAllResponseHeaders = xhr.getAllResponseHeaders;
- xhr.getAllResponseHeaders = function () {
- if ( getAllResponseHeaders() ) {
- return getAllResponseHeaders();
- }
- var allHeaders = "";
- $( ["Cache-Control", "Content-Language", "Content-Type",
- "Expires", "Last-Modified", "Pragma"] ).each(function (i, header_name) {
- if ( xhr.getResponseHeader( header_name ) ) {
- allHeaders += header_name + ": " + xhr.getResponseHeader( header_name ) + "\n";
- }
- return allHeaders;
- });
- };
- return xhr;
- };
- //--------------------------------------------
- $.ajax({
- type: "POST",
- url: "some.php",
- data: { name: "John", location: "Boston" }
- }).done(function( msg ) {
- alert( "Data Saved: " + msg );
- });
- //--------------------------------------------
- $.ajax({
- url: "test.html",
- cache: false
- }).done(function( html ) {
- $("#results").append(html);
- });
- //--------------------------------------------
- var xmlDocument = [create xml document];
- var xmlRequest = $.ajax({
- url: "page.php",
- processData: false,
- data: xmlDocument
- });
- xmlRequest.done(handleResponse);
- //--------------------------------------------
- var menuId = $("ul.nav").first().attr("id");
- var request = $.ajax({
- url: "script.php",
- type: "POST",
- data: {id : menuId},
- dataType: "html"
- });
- request.done(function(msg) {
- $("#log").html( msg );
- });
- request.fail(function(jqXHR, textStatus) {
- alert( "Request failed: " + textStatus );
- });
- //--------------------------------------------
- $.ajax({
- type: "GET",
- url: "test.js",
- dataType: "script"
- });
- //--------------------------------------------
- $.ajaxSetup({
- url: 'ping.php'
- });
- $.ajax({
- // url not set here; uses ping.php
- data: {'name': 'Dan'}
- });
- //--------------------------------------------
- $.ajaxSetup({
- url: "/xmlhttp/",
- global: false,
- type: "POST"
- });
- $.ajax({ data: myData });
- //--------------------------------------------
- $.ajax({
- type: 'POST',
- url: url,
- data: data,
- success: success,
- dataType: dataType
- });
- //--------------------------------------------
- $.post('ajax/test.html', function(data) {
- $('.result').html(data);
- });
- //--------------------------------------------
- // Assign handlers immediately after making the request,
- // and remember the jqxhr object for this request
- var jqxhr = $.post("example.php", function() {
- alert("success");
- })
- .success(function() { alert("second success"); })
- .error(function() { alert("error"); })
- .complete(function() { alert("complete"); });
- // perform other work here ...
- // Set another completion function for the request above
- jqxhr.complete(function(){ alert("second complete"); });
- //--------------------------------------------
- $.post("test.php");
- $.post("test.php", { name: "John", time: "2pm" } );
- $.post("test.php", { 'choices[]': ["Jon", "Susan"] });
- $.post("test.php", $("#testform").serialize());
- $.post("test.php", function(data) {
- alert("Data Loaded: " + data);
- });
- $.post("test.php", { name: "John", time: "2pm" },
- function(data) {
- alert("Data Loaded: " + data);
- });
- $.post("test.php", { name: "John", time: "2pm" },
- function(data) {
- process(data);
- },
- "xml"
- );
- $.post("test.php", { "func": "getNameAndTime" },
- function(data){
- console.log(data.name); // John
- console.log(data.time); // 2pm
- }, "json");
- //--------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- </head>
- <body>
- <form action="/" id="searchForm">
- <input type="text" name="s" placeholder="Search..." />
- <input type="submit" value="Search" />
- </form>
- <!-- the result of the search will be rendered inside this div -->
- <div id="result"></div>
- <script>
- /* attach a submit handler to the form */
- $("#searchForm").submit(function(event) {
- /* stop form from submitting normally */
- event.preventDefault();
- /* get some values from elements on the page: */
- var $form = $( this ),
- term = $form.find( 'input[name="s"]' ).val(),
- url = $form.attr( 'action' );
- /* Send the data using post and put the results in a div */
- $.post( url, { s: term },
- function( data ) {
- var content = $( data ).find( '#content' );
- $( "#result" ).empty().append( content );
- }
- );
- });
- </script>
- </body>
- </html>
- //--------------------------------------------
- $.ajax({
- url: url,
- data: data,
- success: success,
- dataType: dataType
- });
- //--------------------------------------------
- $.get('ajax/test.html', function(data) {
- $('.result').html(data);
- alert('Load was performed.');
- });
- //--------------------------------------------
- // Assign handlers immediately after making the request,
- // and remember the jqxhr object for this request
- var jqxhr = $.get("example.php", function() {
- alert("success");
- })
- .success(function() { alert("second success"); })
- .error(function() { alert("error"); })
- .complete(function() { alert("complete"); });
- // perform other work here ...
- // Set another completion function for the request above
- jqxhr.complete(function(){ alert("second complete"); });
- //--------------------------------------------
- $.get("test.php");
- $.get("test.php", { name: "John", time: "2pm" } );
- $.get("test.php", { 'choices[]': ["Jon", "Susan"]} );
- $.get("test.php", function(data){
- alert("Data Loaded: " + data);
- });
- $.get("test.cgi", { name: "John", time: "2pm" },
- function(data){
- alert("Data Loaded: " + data);
- });
- $.get("test.php",
- function(data){
- $('body').append( "Name: " + data.name ) // John
- .append( "Time: " + data.time ); // 2pm
- }, "json");
- //--------------------------------------------
- $('#result').load('ajax/test.html');
- $('#result').load('ajax/test.html', function() {
- alert('Load was performed.');
- });
- $('#result').load('ajax/test.html #container');
- $('#a').load('article.html');
- $('#b').load('article.html #target');
- //--------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- body{ font-size: 12px; font-family: Arial; }
- </style>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- </head>
- <body>
- <b>Footer navigation:</b>
- <ol id="new-nav"></ol>
- <script>
- $("#new-nav").load("/ #jq-footerNavigation li");
- </script>
- </body>
- </html>
- //--------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- body{ font-size: 12px; font-family: Arial; }
- </style>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- </head>
- <body>
- <b>Successful Response (should be blank):</b>
- <div id="success"></div>
- <b>Error Response:</b>
- <div id="error"></div>
- <script>
- $("#success").load("/not-here.php", function(response, status, xhr) {
- if (status == "error") {
- var msg = "Sorry but there was an error: ";
- $("#error").html(msg + xhr.status + " " + xhr.statusText);
- }
- });
- </script>
- </body>
- </html>
- //--------------------------------------------
- $("#feeds").load("feeds.html");
- $("#objectID").load("test.php", { 'choices[]': ["Jon", "Susan"] } );
- $("#feeds").load("feeds.php", {limit: 25}, function(){
- alert("The last 25 entries in the feed have been loaded");
- });
- //--------------------------------------------
- $.ajax({
- url: url,
- dataType: 'json',
- data: data,
- success: callback
- });
- //--------------------------------------------
- $.getJSON('ajax/test.json', function(data) {
- var items = [];
- $.each(data, function(key, val) {
- items.push('<li id="' + key + '">' + val + '</li>');
- });
- $('<ul/>', {
- 'class': 'my-new-list',
- html: items.join('')
- }).appendTo('body');
- });
- //--------------------------------------------
- // Assign handlers immediately after making the request,
- // and remember the jqxhr object for this request
- var jqxhr = $.getJSON("example.json", function() {
- alert("success");
- })
- .success(function() { alert("second success"); })
- .error(function() { alert("error"); })
- .complete(function() { alert("complete"); });
- // perform other work here ...
- // Set another completion function for the request above
- jqxhr.complete(function(){ alert("second complete"); });
- //--------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <style>img{ height: 100px; float: left; }</style>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- </head>
- <body>
- <div id="images">
- </div>
- <script>
- $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
- {
- tags: "mount rainier",
- tagmode: "any",
- format: "json"
- },
- function(data) {
- $.each(data.items, function(i,item){
- $("<img/>").attr("src", item.media.m).appendTo("#images");
- if ( i == 3 ) return false;
- });
- });</script>
- </body>
- </html>
- //--------------------------------------------
- $.getJSON("test.js", function(json) {
- alert("JSON Data: " + json.users[3].name);
- });
- //--------------------------------------------
- $.getJSON("test.js", { name: "John", time: "2pm" }, function(json) {
- alert("JSON Data: " + json.users[3].name);
- });
- //--------------------------------------------
- $.ajax({
- url: url,
- dataType: "script",
- success: success
- });
- //--------------------------------------------
- $.getScript("ajax/test.js", function(data, textStatus, jqxhr) {
- console.log(data); //data returned
- console.log(textStatus); //success
- console.log(jqxhr.status); //200
- console.log('Load was performed.');
- });
- //--------------------------------------------
- $.getScript("ajax/test.js")
- .done(function(script, textStatus) {
- console.log( textStatus );
- })
- .fail(function(jqxhr, settings, exception) {
- $( "div.log" ).text( "Triggered ajaxError handler." );
- });
- //--------------------------------------------
- $( "div.log" ).ajaxError(function(e, jqxhr, settings, exception) {
- if (settings.dataType=='script') {
- $(this).text( "Triggered ajaxError handler." );
- }
- });
- //--------------------------------------------
- $.ajaxSetup({
- cache: true
- });
- //--------------------------------------------
- jQuery.cachedScript = function(url, options) {
- // allow user to set any option except for dataType, cache, and url
- options = $.extend(options || {}, {
- dataType: "script",
- cache: true,
- url: url
- });
- // Use $.ajax() since it is more flexible than $.getScript
- // Return the jqXHR object so we can chain callbacks
- return jQuery.ajax(options);
- };
- // Usage
- $.cachedScript("ajax/test.js").done(function(script, textStatus) {
- console.log( textStatus );
- });
- //--------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- .block {
- background-color: blue;
- width: 150px;
- height: 70px;
- margin: 10px;
- }</style>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- </head>
- <body>
- <button id="go">» Run</button>
- <div class="block"></div>
- <script>
- $.getScript("/scripts/jquery.color.js", function() {
- $("#go").click(function(){
- $(".block").animate( { backgroundColor: "pink" }, 1000)
- .delay(500)
- .animate( { backgroundColor: "blue" }, 1000);
- });
- });
- </script>
- </body>
- </html>
- //--------------------------------------------
- $('.log').ajaxComplete(function() {
- $(this).text('Triggered ajaxComplete handler.');
- });
- $('.trigger').click(function() {
- $('.result').load('ajax/test.html');
- });
- //--------------------------------------------
- $('.log').ajaxComplete(function(e, xhr, settings) {
- if (settings.url == 'ajax/test.html') {
- $(this).text('Triggered ajaxComplete handler. The result is ' +
- xhr.responseHTML);
- }
- });
- //--------------------------------------------
- $("div.log").ajaxError(function() {
- $(this).text( "Triggered ajaxError handler." );
- });
- $("button.trigger").click(function() {
- $("div.result").load( "ajax/missing.html" );
- });
- //--------------------------------------------
- $( "div.log" ).ajaxError(function(e, jqxhr, settings, exception) {
- if ( settings.url == "ajax/missing.html" ) {
- $(this).text( "Triggered ajaxError handler." );
- }
- });
- //--------------------------------------------
- $("#msg").ajaxError(function(event, request, settings){
- $(this).append("<li>Error requesting page " + settings.url + "</li>");
- });
- //--------------------------------------------
- $.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
- // Modify options, control originalOptions, store jqXHR, etc
- });
- //--------------------------------------------
- var currentRequests = {};
- $.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
- if ( options.abortOnRetry ) {
- if ( currentRequests[ options.url ] ) {
- currentRequests[ options.url ].abort();
- }
- currentRequests[ options.url ] = jqXHR;
- }
- });
- //--------------------------------------------
- $.ajaxPrefilter( function( options ) {
- if ( options.crossDomain ) {
- options.url = "http://mydomain.net/proxy/" + encodeURIComponent( options.url );
- options.crossDomain = false;
- }
- });
- //--------------------------------------------
- $.ajaxPrefilter( "json script", function( options, originalOptions, jqXHR ) {
- // Modify options, control originalOptions, store jqXHR, etc
- });
- //--------------------------------------------
- $.ajaxPrefilter(function( options ) {
- if ( isActuallyScript( options.url ) ) {
- return "script";
- }
- });
- //--------------------------------------------
- $('.log').ajaxSend(function() {
- $(this).text('Triggered ajaxSend handler.');
- });
- $('.trigger').click(function() {
- $('.result').load('ajax/test.html');
- });
- $('.log').ajaxSend(function(e, jqxhr, settings) {
- if (settings.url == 'ajax/test.html') {
- $(this).text('Triggered ajaxSend handler.');
- }
- });
- $("#msg").ajaxSend(function(evt, request, settings){
- $(this).append("<li>Starting request at " + settings.url + "</li>");
- });
- //--------------------------------------------
- $('.log').ajaxStart(function() {
- $(this).text('Triggered ajaxStart handler.');
- });
- $('.trigger').click(function() {
- $('.result').load('ajax/test.html');
- });
- //--------------------------------------------
- $("#loading").ajaxStart(function(){
- $(this).show();
- });
- //--------------------------------------------
- $('.log').ajaxStop(function() {
- $(this).text('Triggered ajaxStop handler.');
- });
- $('.trigger').click(function() {
- $('.result').load('ajax/test.html');
- });
- //--------------------------------------------
- $('.log').ajaxSuccess(function() {
- $(this).text('Triggered ajaxSuccess handler.');
- });
- $('.trigger').click(function() {
- $('.result').load('ajax/test.html');
- });
- //--------------------------------------------
- $('.log').ajaxSuccess(function(e, xhr, settings) {
- if (settings.url == 'ajax/test.html') {
- $(this).text('Triggered ajaxSuccess handler. The ajax response was:'
- + xhr.responseText );
- }
- });
- //--------------------------------------------
- $("#msg").ajaxSuccess(function(evt, request, settings){
- $(this).append("<li>Successful Request!</li>");
- });
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //--------------------------------------------
- //----------------------------------------------------------------------------------------------
- this.ajax_request=function (param, f3) {
- $.ajax ( {
- type: "POST",
- url: this.options.ajax_url,
- data: param} ).done(
- function(html) {f3.targetEl.ajax_result=f3.show(html);});
- }
- //----------------------------------------------------------------------------------------------
- function createHTTP() {
- var r;
- try {
- r = new XMLHttpRequest();
- } catch(e) {
- try {
- r = new ActiveXObject('Msxml2.XMLHTTP');
- } catch (e) {
- r = new ActiveXObject('Microsoft.XMLHTTP');
- }
- }
- return r;
- }
- function ajax_request(param, f3) {
- XHR = createHTTP();
- XHR.stat=0;
- XHR.resp='';
- XHR.f3=f3;
- XHR.onreadystatechange=function() {
- if (this.readyState==4) {
- this.resp=this.responseText;
- this.stat=this.readyState;
- this.f3(this.resp);
- G_Sending=false;
- }
- else if (this.readyState==3) {
- this.stat=this.readyState;
- }
- }
- XHR.open('POST','req4.php',true);
- XHR.setRequestHeader("Content-type","application/x-www-form-urlencoded");
- XHR.send(param);
- }
- //----------------------------------------------------------------------------------------------
- function ajax_request(param, f3) {
- if (gl_loading)
- return;
- gl_loading=true;
- showLoading(true);
- //----------------------------
- function showLoading(on) {
- if (on) {
- $('#ajax_wait').css('width',screen.width+'px');
- $('#ajax_wait').css('height',screen.height+'px');
- $('#ajax_wait').css('display','block');
- }
- else {
- $('#ajax_wait').css('display','none');
- }
- }
- //----------------------------
- function onSuccess(html) {
- f3(html);
- showLoading(false);
- gl_loading=false;
- }
- //----------------------------
- function onAjaxError(xhr,status) {
- showLoading(false);
- gl_loading=false;
- var errinfo = {errcode: status};
- if (xhr.status!=200) {
- errinfo.message=xhr.statusText;
- }
- else {
- errinfo.message='incorrect data';
- }
- onLoadError(errinfo);
- }
- //----------------------------
- function onLoadError(errinfo) {
- var mag = 'error '+errinfo.errcode;
- if (errinfo.message)
- msg+=' :'+errinfo.message;
- alert(msg);
- }
- //----------------------------
- if (location.hostname=='localhost')
- req_url='../learn/picport/req4.php';
- else
- if (location.hostname.indexOf('dmkim1.bget.ru')!=-1)
- req_url='/learn/picport/req4.php';
- else
- if (location.hostname.indexOf('ubezhishche.ru')!=-1)
- req_url='reqajax.php';
- else
- req_url='../phpnew/picport/req4.php';
- $.ajax( {
- type: 'GET',
- url: req_url,
- data: param,
- success: onSuccess,
- error: onAjaxError,
- cache: false
- });
- }
- //----------------------------------------------------------------------------------------------
- function createHTTP() {
- var r;
- try {r= new XMLHttpRequest() }
- catch(e) {
- try {r=new ActiveXObject('Msxml2.XMLHTTP');}
- catch(e) {r=new ActiveXObject('Microsoft.XMLHTTP')}
- }
- return r;
- }
- //--------------------------------------------------------
- function ajax_request(param,el) {
- XHR=createHTTP();
- XHR.el=el;
- XHR.onreadystatechange= function() {
- //alert(this.readyState);
- if (this.readyState==4) {
- //if (this.status=200) {
- el3=document.getElementById(this.el);
- el3.innerHTML=this.responseText
- //}
- G_Sending=false;
- }
- else if (this.readyState==3) {
- el3=document.getElementById(this.el);
- el3.innerHTML='Waiting...';
- }
- }
- XHR.open('POST','upload3.php',true);
- XHR.setRequestHeader("Content-type","application/x-www-form-urlencoded");
- XHR.send(param);
- //XHR.open('GET','upload3.php?'+param,true);
- //XHR.setRequestHeader("Content-type","application/x-www-form-urlencoded");
- //XHR.send(null);
- }
- //----------------------------------------------------------------------------------------------
- this.ajax_request = function (param, f3) {
- $.ajax ( {
- type: 'POST',
- url: this.options.ajax_url,
- data: param
- }
- ).done(
- function(html) {
- f3.statEl.ajax_result=f3.show(html);
- my.wr('finished: '+f3.statEl.testb);
- my.loading=false;
- }
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement