What would happen if some random webpage made an Ajax request for

I run a localhost-only webserver (PHP’s built-in one) for all my admin panels and whatnot on my machine. I’m worried that, if any random webpage has a JavaScript snippet which makes an Ajax call to , and I visit that webpage, it will make my browser (Firefox) fetch whatever data is returned from that URL and be able to use it, for example to send it back to their own server in another Ajax request.

Let’s assume that returns my entire diary since 1958. Or anything equally sensitive. I definitely don’t ever want it to interact with anything other than my Firefox browser, but from what I can reckon, this could be a massive privacy/security issue. I hope I’m wrong about my assumption that this request would be allowed. I hope that it has some kind of “cross-domain policy” blocking it or something. Especially since it’s from, which should be some kind of special case.

What would stop it from doing this? What am I missing in my reasoning?

How to organize big amounts of texts after several Ajax calls?

Sorry if this is a dumb question, I’m trying to figure out the more appropiate way to deal with some content presentation.

I have 10 category buttons on a page, each one is assigned to a div.

On those divs, I would show Ajax results, on the click of their specific button.

However, if people enabled all of the 10 buttons, the amount of text that would be shown would be too large, and unmanageable from a user interface point of view.

How should I resolve this situation and create an appropiate interface?

Is Ajax pagination a possible solution for me? How to combine separate Ajax calls with a generic pagination system? Otherwise, can you point me to some other ideas?


How to implement an infinite scroll or Ajax load more

My site is www.grubnglug.co.uk. I use geomywp to search/filter and display posts and do not want to change it.

My question is, how can I implement infinite scrolling or Ajax load more button functionality on the posts, so i can get rid of the ugly pagination buttons.

I tried various plugins but they all load the posts independently rather than integrating with geomywp /it’s template for displaying postsand infinitely loading them.

As a result I end up with two lots of posts – one infinitely loaded and the other as it is currently, with the pagination buttons.

I don’t have coding skills beyond minor tweaks. I’m lost ­čÖü

how to filter posts by category without page load (ajax) in wordpress?

I Tried this code, here: http://rankonone.com/dev/profdharm/monthly-rashifal/

August, October, September are categories, I want to show post below without page load where currently title and date.

Can anyone please help?

//This is category filter:  <ul class="xiong-filters"> <?php        //This one is to display All in your category.       // Do not use show_option_all parameter since it includes all categories not just one your displaying       $  args= array(           'include'          =>   2, //Put here ID of your category         'title_li'          => __('')       );     wp_list_categories( $  args );   ?>   <?php        //This one displays subcategories of your category       $  args= array(           'child_of'          =>   2, //Put here parent category         'title_li'          => __('')       );     wp_list_categories( $  args );   ?> 

<!--Post LOOP  -->  <?php if ( have_posts() ) :?>   <div id="main-content" class="row">     <div id="inside">       <div class="container">    <?php while ( have_posts() ) : the_post(); ?>       <article> <a class="xiong-articlebox" href="<?php the_permalink();?>">     <header>         <h3><?php the_title( );?></h3>         <p><em><?php the_date( 'j.n.Y'); ?> </em></p>          </header>          <p><?php the_excerpt();?></p>        </a>    </article>    <?php endwhile; endif; ?>   </div><!-- container-->   

//AJAX Filters jQuery(function(){ var mainContent = jQuery('#main-content'),     cat_links = jQuery('ul.xiong-filters li a');      cat_links.on('click', function(e){          e.preventDefault();         el = $  (this);         var value = $  el.attr("href");         mainContent.animate({opacity:"0.5"});         mainContent.load(value + " #inside", function(){             mainContent.animate({opacity:"1"});         });         jQuery( "li" ).removeClass( "current-cat" );          jQuery(this).closest('li').addClass("current-cat");     }); });   //Function.php //ENQUEUE SCRIPTS HERE function xiong_theme_scripts() { //Ajax filter scripts wp_register_script( 'ajax', get_template_directory_uri() . '/js/ajax.js', array( 'jquery' ), '1.0.0', true );     wp_enqueue_script( 'ajax' );} add_action( 'wp_enqueue_scripts', 'xiong_theme_scripts' ); 

Sharepoint REST api: wasn’t $.Ajax supposed to make asynchronous calls?

I don’t understand why my code is running synchronous. At least it is what the attached print-screen shows. Are my assumptions correct?

<script src="../SiteAssets/js/lib/jquery-2.2.0.min.js"></script>  <script type="text/javascript" src="_layouts/15/sp.runtime.js"></script> <script type="text/javascript" src="_layouts/15/sp.js"></script> <script type="text/javascript" src="_layouts/15/sp.RequestExecutor.js"></script>  <script>     var oWeb = "https://xxxxxxxxx.sharepoint.com/sites/edpsaomanoel/";      $  (document).ready(function () {         getListItems();         executorGetListItems();     });      var endpointUrl = "_api/web/lists/getbytitle('acoes')/items/?$  select=Id,Title,DueDate,PercentComplete&$  top=200";     var acceptHeaders = {"Accept": "application/json; odata=minimalmetadata"}      function onFail (data, errorCode, errorMessage) {         console.log("Error:",errorMessage,errorCode,data);     }      function executorGetListItems() {             var executor;         executor = new SP.RequestExecutor(oWeb);          executor.executeAsync({             url: endpointUrl,             method: "GET",             headers: acceptHeaders,             error: onFail,             success: function (data){                 console.log("ok executor",JSON.parse(data.body).value; //data.body.constructor === String                      }         });     }      function getListItems() {             $  .ajax({             url: oWeb + ""+ endpointUrl,             method: "GET",             headers: acceptHeaders,             error: onFail,             success: function (data){                 console.log("ok ajax",data.value); //data.value === Object             }         });     }  </script> 

enter image description here

validar dato repetido antes de procesar un ajax

Estoy usando struts 2 y ajax. El problema es cuando quiero evitar que se ingrese un dato repetido a mi base de datos.

Este es el codigo, me valida el primer objeto del array, pero cuando ingreso el segundo valor repetido, me deja registrar.

function grabarHerramienta(){ var json,nom,sto,mon,pre,fec,ser,tip;  nom = $  ("#idNombre").val(); sto = $  ("#idStock").val(); mon = $  ("#idMoneda:checked").val(); pre = $  ("#idPrecio").val(); fec = $  ("#idFecha").val(); ser = $  ("#idSerie").val(); tip = $  ("#idTipo").val();  json = JSON.stringify({     nombre:nom,     stock:sto,     moneda:mon,     precio:pre,     fecha:fec,     serie:ser,     codTipoHerramienta:tip });   $  .get("listarHerramientas",{}, function(response){     $  .each(response.listaHerramientas, function(){         if (nom == this.nombre){             console.log("Ya existe");             return false;         } else {             $  .ajax({                 url: 'guardarHerramienta',                 type: 'POST',                 data: {JSONHerramienta:json},                 success:function(data){                     if (data.dataMensaje == 1){                         console.log(data);                         mostrarHerramienta();                         $  ("#exampleModal").modal("hide");                     } else {                         console.log("Error");                     }                 }             });         }     }) }) 

Me registra , pero no quiero que ingrese el mismo valor.

Update / refresh mini cart, after custom AJAX add_to_cart event

I need help

In my custom single-product.php template, I added the button

public function AddToCartButton() {     global $  product;      if($  product->is_type('variable') || $  product->get_stock_status() !== 'instock') {         $  disabled_btn_class = 'btn-am--disabled';     } else {         $  disabled_btn_class = '';     }      $  echo = '<form class="cart single-product-cart" method="post" action="woocommerce_ajax_add_to_cart" enctype="multipart/form-data">';     $  echo .= '<button type="submit" class="single_add_to_cart_button button alt btn-am btn-am--red '. $  disabled_btn_class .'" data-url="'. admin_url("admin-ajax.php").'"> ' . esc_html( $  product->single_add_to_cart_text() ) .'</button>';     $  echo .= '<input type="hidden" name="add-to-cart" value="'. absint( $  product->get_id() ) .'" />';     $  echo .= '<input type="hidden" name="product_id" value="'. absint( $  product->get_id() ) .'" />';     $  echo .= '<input type="hidden" name="quantity" value="1" />';     $  echo .= '<input type="hidden" name="variation_id" class="variation_id" value="0" />';     $  echo .= '</form>';      return $  echo; } 

Custom AJAX call

public function __construct() {     add_action('wp_ajax_woocommerce_ajax_add_to_cart', [$  this, 'ajax_add_to_cart']);     add_action('wp_ajax_nopriv_woocommerce_ajax_add_to_cart', [$  this, 'ajax_add_to_cart']); }  function ajax_add_to_cart() {     $  product_id         = apply_filters('woocommerce_add_to_cart_product_id', absint($  _POST['product_id']));     $  quantity           = empty($  _POST['quantity']) ? 1 : wc_stock_amount($  _POST['quantity']);     $  variation_id       = absint($  _POST['variation_id']);     $  passed_validation  = apply_filters('woocommerce_add_to_cart_validation', true, $  product_id, $  quantity);     $  product_status     = get_post_status($  product_id);      if ($  passed_validation && WC()->cart->add_to_cart($  product_id, $  quantity, $  variation_id) && 'publish' === $  product_status) {          do_action('woocommerce_ajax_added_to_cart', $  product_id);          if ('yes' === get_option('woocommerce_cart_redirect_after_add')) {             wc_add_to_cart_message(array($  product_id => $  quantity), true);         }      } else {          $  data = array(             'error' => true,             'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($  product_id), $  product_id));          echo wp_send_json($  data);     }      wp_die(); } 

This code works, and if refresh page, item added to cart, but this not work with hook woocommerce_add_to_cart_fragments

And in my functions.php I have this code for refresh update cart

add_filter( 'woocommerce_add_to_cart_fragments', 'wc_mini_cart_ajax_refresh' ); function wc_mini_cart_ajax_refresh( $  fragments ) { $  fragments['#mcart-stotal'] = '<div id="mcart-stotal" class="mini-cart-footer__total">'.WC()->cart->get_cart_subtotal().'</div>'; ob_start(); echo '<div id="mcart-widget">'; woocommerce_mini_cart(); echo '</div>'; $  fragments['#mcart-widget'] = ob_get_clean();  return $  fragments; 


And this hook works fine, but not for my custom AJAX button, why this happen?

Validacion de un formulario dentro de un Modal con Jquary, Ajax y Php

Deseo que mi Formulario que se encuentra dentro de mi Modal fuincione, pero no lo eh logrado, no se ejecuta ninguna de las opciones. deseo hacer un login de un administrador de la pagina la cual quiero que se efectue el fomrulario en el modal, buscando en la base de datos con php para ver si es valido el usuario. No me funciona pero tampoco en el inspector no me muestra ningun error, ni en el console me muestra el console.log que tengo en mi js.

<button type="button" id="ad"><img id="admi" src="img/admin.png"></button>

$  (function(){      $  ("#fmodal").on("submit", function (e) {         e.preventDefault();         $  .ajax({             url: "php/vale.php",             method: "POST",             data: $  (this).serialize(),             success: function (result) {                 console.log(result);                 if(parseInt(result)){                     console.log(result);                     window.location.href="admi.html"                 }else{                     console.log(result);                     alert("Usuario Invalido");                 }              }         });     }); }); 

Es Este mi codigo html del modal.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="modal" tabindex="-1" role="dialog" id="modaladmin">         <div class="modal-dialog" role="document">             <div class="modal-content">                 <div class="modal-header" style="background-color: #970007;">                     <font size=2 color="white">                         <h5 class="modal-title" align="center">Iniciar Sesi├│n</h5>                     </font>                 </div>                 <form method="POST" id="fmodal">                     <div class="modal-body">                     <p>Por favor, si es Administrador ingrese los siguentes datos:</p>                     <input type="text" name="adcor" id="adcor" placeholder="Usuario">                     <input type="password" name="contra" id=contra placeholder="Contrase├▒a">                     </div>                     <div class="modal-footer" style="background-color: #F4F4F4;" align="center">                     <button type="submit"  id="mis">Siguiente</button>                 </div>             </form>              </div>         </div>     </div> 

Es etes mi codigo php para validar mi formulario con la base de datos

    <?php include "conexion.php"; $  link=conectarse();  $  usuario=$  _POST['adcor']; $  contrase├▒a=$  _POST['contra'];  $  query ="SELECT * FROM Admin WHERE Usuario='$  usuario' AND Contrase├▒a='$  contrase├▒a'"; $  result=mysqli_query($  link, $  query); $  num_rows = mysqli_num_rows($  result);  if($  num_rows == 1){          echo 1;     }else{          echo 0;     }  mysqli_close($  link);   ?> 

Obtener valores ajax del filtro de b├║squeda de un sitio web para scraping en php

Estoy haciendo scraping a un sitio web externo. Mi objetivo es obtener los datos de una tabla que se muestra en el sitio web externo. Los datos se van mostrando seg├║n los valores de un combobox (al elegir una opci├│n del combobox, ├ęste habilita las opciones de otro combobox y as├ş sucesivamente), finalmente se presiona un bot├│n de “b├║squeda”, el cual lista los datos que deseo obtener en una tabla de tipo datetable. ┬┐C├│mo puedo obtener los valores de esta tabla del sitio web externo para posteriormente, listarlas en una tabla en mi sitio web propio?