php script, iki ajax isteklerini alır tek verir?

1 Cevap php

I'll start from the beginning. I'm building a wordpress plugin that does double duty, in that it can be inserted in to a post via a shortcode, or added as a sidebar widget. All it does is output some js to make jquery.post requests to a local php file. The local php file makes a request to a webservice for some data. (I had to do it this way instead of directly querying the web service with jquery.ajax because the url contains a license key that would be public if put in the js).

Her neyse, ben kenar çubuğu widget'ı ve SHORTCODE yoluyla eklenti çıkışını istekleri işin sadece bir hem de wordpress blog bir sayfa görüntüleme olduğum zaman. Ben o php script geri bir yanıt alır çalışır anlamına gelir. Manuel olarak söyledim sayfa normalde ikisinin de çalışması yüklendikten sonra.

Web sayfası görünümü -> benim php script 2 post istekleri göndermek -> hem elemanları açılan olmalı, ama sadece bir tanesidir.

Benim php script sadece budur:

<?php
    if(isset($_POST["zip"])) {
         // build a curl object, execute the request, 
         // and basically just echo what the curl request returns.
    }
?>

Oldukça basit.

Burada bazı insanlar görmek istedim bazı js olduğunu:

function widget_getActivities( zip ){
    jQuery("#widget_active_list").text("");
    jQuery.post("http://localhost/wordpress/wp-content/ActiveAjax.php", { zip: zip}, 
		function(text) {
			jQuery(text).find("asset").each(function(j, aval){
				var html = "";
				html += "<a href='" + jQuery(aval).find("trackback").text() + "' target='new'> " +  jQuery(aval).find("assetName").text() + "</a><b> at </b>";

				jQuery("location", aval).each(function(i, val){
					html += jQuery("locationName", val).text() + " <b> on </b>";
				});

				jQuery("date", aval).each(function(){
					html += jQuery("startDate", aval).text();
				<!--jQuery("#widget_active_list").append("<div id='ActivityEntry'>" + html + " </div>");-->
				jQuery("#widget_active_list")
					.append(jQuery("<div>")
						.addClass("widget_ActivityEntry")
						.html(html)
						.bind("mouseenter", function(){
							jQuery(this).animate({ fontSize: "20px", lineHeight: "1.2em" }, 50);  
						})
						.bind("mouseleave", function(){
							jQuery(this).animate({ fontSize: "10px", lineHeight: "1.2em" }, 50);  
					})
					);

				});
			});
		});
}

Şimdi önüne değil 'widget_' ile önüne her şeyin dışında bu bir aynıdır başka işlevi yoktur düşünün. Bu iki işlev üzerinden ayrı denilen olsun:

jQuery(document).ready(function(){
    w_zip = jQuery("#widget_zip").val();
	widget_getActivities( w_zip );
	jQuery("#widget_updateZipLink").click(function() { //start function when any update link is clicked
		widget_c_zip = jQuery("#widget_zip").val();
		if (undefined == widget_c_zip || widget_c_zip == "" || widget_c_zip.length != 5)
			jQuery("#widget_zipError").text("Bad zip code");
		else
			widget_getActivities( widget_c_zip );

	});
})

I can see in my apache logs that both requests are being made. I'm guessing it is some sort of race condition but that doesn't make ANY sense. I'm new to all this, any ideas?

EDIT: Ben bir alt-optimal çözüm ile geldim. Ben eklenti de sayfada kullanılan ediliyor eğer benim Widget tespit var, ve bu yüzden isteği yapmadan önce 3 saniye bekler eğer. Ama bu aynı şey sorun korkutucu php komut dosyası içinde olduğuna inanıyorum, çünkü birden fazla müşteri, benim php komut dosyası istekleri birini tetikler, aynı zamanda bir sayfa isteği gerçekleştirmek durumunda ne olacak bir his var.

1 Cevap

Beni gerçekten bir şey anlamaya için gerçekten yeterli değil bilgi ...

Ancak denemek için bir şey kundakçı almak ve tepki istekleri her biri için ne olduğunu görmek için.

Başka bir soru ... Eğer id tarafından doldururken olabilir? Eğer öyleyse, o zaman tek bir sayfada iki kez aynı kimliğe sahip, ve bu şeyleri karışıklık olmasından kaynaklanıyor olabilir. Bunu online varsa size yardım etmek çok daha kolay olacaktır.


Edit:

Bir kaç yorum ... Ancak ... Bir şey bu çözülecektir emin değilim ...

 <!--jQuery("#widget_active_list").append("<div id='ActivityEntry'>" + html + " </div>");-->

Html kullanılan ve Javascript vidalama olabilir zaman Bildiğim kadarıyla kullanmak yorumun türünü bildiğiniz gibi tek etkili yoktur. Ile değiştirin / /

jQuery("#widget_active_list").append(jQuery("<div>")
                                     .addClass("widget_ActivityEntry")
                                     .html(html)
                                     .bind("mouseenter", function(){
                                          jQuery(this).animate({ fontSize: "20px", lineHeight: "1.2em" }, 50);  
                                     })
                                     .bind("mouseleave", function(){
                                          jQuery(this).animate({ fontSize: "10px", lineHeight: "1.2em" }, 50);  
                                     })
                             );

İkincisi ... bütün o blok son iç içe. Ancak bir etkiye sahip gibi görünmüyor herbirinin, o onunla karıştırmasını imkansız değildir.

Aslında bir fark verme olmayabilir iken tüm Son, muhtemelen xml yanıt türünü ayarlama yapılmalıdır. Php hem http başlıklarını kullanarak ve fonksiyonunun son argümanını kullanarak. yani

header("Content-Type: application/xml");

ve

jQuery.post("http://localhost/wordpress/wp-content/ActiveAjax.php", { zip: zip}, thefunctionhere, xml);

If this doesn't help, my suggestion for a sub-optimal solution, is to use a get request instead, ve add a rveom parameter that isn't taken into account to both requests, however make it the same for each request, but different every time you go to the page. That way the browser will cache the request for the first one, ve not query the server a second time, but it won't cache it for when the person comes to the page again.