i have try different solutions from this media but still it does not work for me please help me.  function get_category(){ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) { var ans = document.getElementById("sell_panel"); ans.innerHTML  = xmlhttp.responseText; } } xmlhttp.open("GET", "includes/get_category.php", true); xmlhttp.send();  } `$('.item_btn').on('click', function () {// HERE IS MY CLICK EVENT alert("helo"); });`  AND MY get_category.PHP FILE IS;  &lt;?php include("database.php"); $db = new Database();    $sql = "SELECT DISTINCT category FROM stock"; $result = mysql_query($sql); if($result === FALSE) {  die(mysql_error()); // TODO: better error handling }    while($cat = mysql_fetch_array($result)){  echo " &lt;div class='item_btn' id='{$cat[0]}'&gt;//HERE IS THE DIV  &lt;label&gt;{$cat[0]}&lt;/label&gt;  &lt;/div&gt;   "; }     ?&gt;   I HAVE TRIED delegate() also it did not work for me and i have heard about to trigger my event handler in ajax but i dont know how to do it please help me guys
112
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.  This happens on page ready and works just fine.  The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.  I have found this plugin (), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.
16373
How do I pass have a Javascript script request a PHP page and pass data to it? How do I then have the PHP script pass data back to the Javascript script?  client.js:  data = {tohex: 4919, sum: [1, 3, 5]}; // how would this script pass data to server.php and access the response?   server.php:  $tohex = ... ; // How would this be set to data.tohex? $sum = ...; // How would this be set to data.sum? // How would this be sent to client.js? array(base_convert($tohex, 16), array_sum($sum))
37250
I have create a form with form_validate and form_submit functions.  Using Firefox, everything is OK so the problem is not about an error in functions names.  Using Chrome, when I click on submit the page is just reloaded. I have added to my code drupal_debug to track the process into validate function and submit function. System not going into these functions.  I have no ideas about how form_validate function could be linked with choice of browser.  UPDATE : I have found more details about the cause of the problem :  To submit the form, user not click on the submit button directly. He have to click on an other button which launch js function.  At the end of the js function, I use jQuery( "#edit-continue" ).trigger( 'click' ) to simulate click on the real submit button.  I have tried to click directly on the real submit button and it is working but with trigger I see the ajax GIF of drupal but there is no passage to my form_validate function.  So, I really need to know how drupal can make the difference between a real click and an emulated one. And the most important how can I do to fix or skirt this problem.
57784
I'm working on a offline version of a website using jQuery and some xml files. I'm running in to a problem in jQuery when I do a $.ajax call on a xml file jQuery throws a error.  When I look at the error I can tell its loading the XML file because its in the error's responceText property. It seams to work just fine in Firefox.  This is how my call looks  $.ajax({     type: "GET",     url: "Modules/" + ModuleID + "/ModuleContent.xml",     dataType: "xml",     success: function(x) { xml = x; ProcessXML(); },     error: function(x) { alert(x.responceText); } });   When I run this on a web server it works just fine. Its only when I run it from the file its self when I have this problem.  Any ideas on how I can make this work in IE?  Edit: I found the answer to my problem.
91776
I have created a shortcode that retrives and displays a form.The content of the attribute in HTML.   function check_my_login( $atts)     {          return '&lt;form action="" name="" method="post" enctype="multipart/form-data"&gt;                &lt;div class="form-group"&gt;                     &lt;label for="description"&gt;Project Description&lt;/label&gt;                     &lt;textarea name="p_description" placeholder="Project Description" class="form-control"&gt;&lt;?php if (isset($_POST['p_description']) &amp;&amp; $_POST['p_description'] != '') echo $_POST['p_description'] ?&gt;&lt;/textarea&gt;                 &lt;/div&gt;                  &lt;div class="form-group"&gt;                     &lt;label&gt;Project Attachment&lt;/label&gt;                     &lt;input type="file" name="p_attachment"&gt;                 &lt;/div&gt; &lt;/form&gt;';     }     add_shortcode( 'kentaUser', 'check_my_login' );   Now use this shortcode inside the Post/page.   Like this    &lt;div class='manage_page'&gt;[kentaUser]&lt;/div&gt;  But my shortcode content display out side the div.Display upper side in post/page content.  &lt;div class='manage_page'&gt;&lt;/div&gt;    Any one short out this problem.
119247
I got a set of meta boxes on a custom post type. Two of them are simple input/text-type fields, that should have autocompleted input:   A) Another Custom Post Type B) Users   Now I have the problem that I need to somehow trigger the autocomplete event. So far I have this pretty simple definition:  jQuery( document ).ready( function ($)         {             $( '#some_id' ).autocomplete(             {                  minLength: 2                 ,source:    "&lt;?php print 'SOME_STRING'; ?&gt;"             } );         } );   which gives me the following answer in the console, when I enter "zz":      GET http:// localhost/wordpress/wp-admin/SOME_STRING?term=zz 404 (Not Found)   Point is that I need to run a query (as you can see above) and need to root the request for the source option/argument from autocomplete somehow to a php callback.  I hope someone can explain me how I'd get around this. Thanks (and merry christmas in case you read this :) !
99580
I am new to Salesforce development. I made a trigger that creates a new asset record and autofills some of the fields on said record. What I want ultimately would be a button that I can put on the "Products" related list on the opportunity page that does what my trigger does. From what I understand, I can't just call my trigger on the button click, and I have to create a VF page or an Apex class that uses the trigger's logic. Does anyone know how I would go about doing this? Here's my code:  trigger ConvertOpportunitiesToAssets on Opportunity (after update) {      List&lt;Asset&gt; a = new List&lt;Asset&gt;();     OpportunityLineItem oli = new OpportunityLineItem();      for(Opportunity o: Trigger.new)     {                   a.add( new Asset(             PSI_Supplier__c = o.Supplier__c,             PSI_Opportunity__c = oli.Product2Id,             AccountId = o.Accountid,             Name = oli.Product2Id,             Product2Id = oli.Product2Id,             Product_Name__c = oli.Product_Name__c             ));            }     insert a; }   Thanks in advance!  UPDATE So I tried making the trigger into a class and button (thanks sfdcfox!), but now it won't work. Here's what I've got:      global class OpportunityWS{     webservice static void createAsset(Id opportunityId)     {         List&lt;Asset&gt; a = new List&lt;Asset&gt;();         Opportunity o = new Opportunity();         OpportunityLineItem oli = new OpportunityLineItem();          a.add( new Asset(             PSI_Supplier__c = o.Supplier__c,             PSI_Opportunity__c = oli.Product2Id,             AccountId = o.Accountid,             Name = oli.Product2Id,             Product2Id = oli.Product2Id,             Product_Name__c = oli.Product_Name__c             ));                 insert a;      } }  {!RequireScript("/soap/ajax/34.0/connection.js")} {!RequireScript("/soap/ajax/34.0/apex.js")} function success() { var alertString="Success!";  alert(alertString);  } function error() { var alertString="Error!";  alert(alertString);  } sforce.connection.sessionId = "{!$Api.Session_ID}"; sforce.apex.execute("OpportunityWS", "createAsset", { opportunityId: "{!Opportunity.Id}" }, { onSuccess: success, onFailure: error });   I can't tell if it's something wrong with the class or the button. I think it must be the class.  UPDATE(AGAIN) Alright so I followed Doug's advice and tried to use the opportunityId to query the opportunity and opportunityLineItem sobjects, was able to compile without errors. But now I'm getting the error message that I made in the button thrown and the asset isn't being created. Unfortunately, I haven't been able to track down the issue. Here's the OpportunityWS apex class that I've updated since last edit:  global class OpportunityWS{ webservice static void createAsset(Id opportunityId) {     List&lt;Asset&gt; a = new List&lt;Asset&gt;();     List&lt;Opportunity&gt; o = [SELECT Supplier__c, Accountid FROM Opportunity WHERE Id = :opportunityId];     List&lt;OpportunityLineItem&gt; oli = [SELECT Product2Id, Product_Name__c FROM OpportunityLineItem WHERE Id = :opportunityId];      a.add( new Asset(         PSI_Supplier__c = o[0].Supplier__c,         PSI_Opportunity__c = oli[0].Product2Id,         AccountId = o[1].Accountid,         Name = oli[0].Product2Id,         Product2Id = oli[0].Product2Id,         Product_Name__c = oli[1].Product_Name__c         ));             insert a; }   }
24892
I have a a bunch of li's that are a blog but i want to show them enlarged in a colorbox. Therefore I need to know which li I clicked so I can get that ID and use that in my query to get all the date for that post.  Now I thought that the best way is to retrieve the blog id with jQuery and then use that to add to my query in the footer.       &lt;li id="&lt;?php the_ID;?&gt;"&gt;blog&lt;/li&gt;     &lt;li id="&lt;?php the_ID;?&gt;"&gt;blog&lt;/li&gt;     &lt;li id="&lt;?php the_ID;?&gt;"&gt;blog&lt;/li&gt;     &lt;li id="&lt;?php the_ID;?&gt;"&gt;blog&lt;/li&gt;      //My colorbox inline frame     &lt;?php query_posts( 'p="the_ID_of_clicked_li' ); ?&gt;      etc etc   I think this can be done with AJAX but is there a more simple method and give me a clean URL?  I haven't AJAX in projects before, so I am a beginner with that.  Any thoughts would be appreciated
61270
if (strstr($_SERVER['REQUEST_URI'],'index.php')) {     header('HTTP/1.0 404 Not Found'); }   Why wont this work? I get a blank page.
7523
How do I send a cross-domain POST request via JavaScript?  Notes - it shouldn't refresh the page, and I need to grab and parse the response afterwards.
123225
I'm looking for something like alert(), but that doesn't "pause" the script.  I want to display an alert and allow the next command, a form submit(), to continue. So the page will be changing after the alert is displayed, but it won't wait till the user has clicked OK.  Is there something like this or is it just one of those impossible things?
88037
So i'm trying to submit a form using ajax, in my form i have the following:          $form['actions']['#type'] = 'actions';         $form['actions']['submit'] = array(         '#type' =&gt; 'submit',         '#value' =&gt; $this-&gt;t('OK'),         '#button_type' =&gt; 'primary',         '#prefix' =&gt; '&lt;div class="tc btn_pay relative"&gt;',         '#suffix' =&gt; '&lt;/div&gt;                         &lt;/div&gt;',         '#attributes' =&gt; array(             'class' =&gt; array('proximabold', 'tc', 'transition', 'no-underline', 'ph3', 'pv2', 'mb2', 'dib', 'white'),         ),         '#ajax' =&gt; [             'event' =&gt; 'click',             'callback' =&gt; '::updateTable',             'wrapper' =&gt; 'table-wrapper',             'progress' =&gt; [                 'type' =&gt; 'throbber',                 'message' =&gt; t('Verifying entry...'),             ],         ],     );   and a simple updateTable function:  public function updateTable(array $form, FormStateInterface $form_state) {     return "Hello World"; }   But when i click on submit i get the error: An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (2 MB) that this server supports.  I knew that the error is server side (Maybe i'm wrong), so i went to php.ini (i use PHP7) and update the following lines:  post_max_size = 6144M memory_limit = 6144M upload_max_filesize = 6144M max_file_uploads = 1000   but without luck, this configuration shouldn't be necessary as the request size is only 1.5KB
26203
I'm trying to direct a browser to a different page. If I wanted a GET request, I might say  document.location.href = 'http://example.com/q=a';   But the resource I'm trying to access won't respond properly unless I use a POST request. If this were not dynamically generated, I might use the HTML  &lt;form action="http://example.com/" method="POST"&gt;   &lt;input type="hidden" name="q" value="a"&gt; &lt;/form&gt;   Then I would just submit the form from the DOM.  But really I would like JavaScript code that allows me to say  post_to_url('http://example.com/', {'q':'a'});   What's the best cross browser implementation?  Edit   I'm sorry I was not clear. I need a solution that changes the location of the browser, just like submitting a form. If this is possible with , it is not obvious. And this should not be asynchronous, nor use XML, so Ajax is not the answer.
7478
I would like to upload a file asynchronously with jQuery.     $(document).ready(function () {     $("#uploadbutton").click(function () {         var filename = $("#file").val();          $.ajax({             type: "POST",             url: "addFile.do",             enctype: 'multipart/form-data',             data: {                 file: filename             },             success: function () {                 alert("Data Uploaded: ");             }         });     }); }); &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"&gt;&lt;/script&gt; &lt;span&gt;File&lt;/span&gt; &lt;input type="file" id="file" name="file" size="10"/&gt; &lt;input id="uploadbutton" type="button" value="Upload"/&gt;     Instead of the file being uploaded, I am only getting the filename. What can I do to fix this problem?
104708
I'm working on a web page where I'm making an AJAX call that returns a chunk of HTML like:   &lt;div&gt;   &lt;!-- some html --&gt;   &lt;script type="text/javascript"&gt;     /** some javascript */   &lt;/script&gt; &lt;/div&gt;   I'm inserting the whole thing into the DOM, but the JavaScript isn't being run.  Is there a way to run it?    Some details: I can't control what's in the script block (so I can't change it to a function that could be called), I just need the whole block to be executed.  I can't call eval on the response because the JavaScript is within a larger block of HTML.  I could do some kind of regex to separate out the JavaScript and then call eval on it, but that's pretty yucky.  Anyone know a better way?
93215
I was wondering if we can trigger a PHP file on every WordPress post or page if a certain condition is met. Let me detail what I want.   Can we write a simple PHP script that will be automatically loaded on every WP post and page. Once loaded, the script should scan the HTML and if it finds a specific DIV tag with the ID myID it should trigger another PHP file (let's say script.php). Once the target PHP file has been triggered or executed, the target PHP file (script.php) should be able to automatically fetch the URL of the post or page that triggered the file and store it in a variable.   Any ideas??
15556
I am afraid that listing doesn't support javascript.  \begin{lstlisting}[language=javascript] ... \end{lstlisting}   What am I doing wrong?