Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8762135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:27:18+00:00 2026-06-13T15:27:18+00:00

I’m new to Javascript. The code for a jQuery-ajax-php-cooperation does strange things. It works

  • 0

I’m new to Javascript. The code for a jQuery-ajax-php-cooperation does strange things. It works – sometimes.

This is what I want to do:

  • make some settings in a form (works)
  • read JSON-file after pressing submit-button (works)
  • loop the JSON-items, extract the values of each item and form a parameter-string (problem is here: loop is not (always) executed in the button-pressed-function)
  • send parameter-string built from each items values to PHP-file (works if loop is entered)
  • receive the response from the PHP-file (html-tag) (works)
  • update a form element with the response value (not yet implemented, actually show an alert with the PHP-response for debugging purposes)

The JSON file is valid (tested).
The HTML-Page is valid HTML5 (tested).
The PHP-script works and returns a valid HTML-Image-Tag (tested).

When I press the button, no responses from the PHP-file are displayed in the alert I implemented for debugging purposes. But this works:

  • reload page
  • open Firebug
  • set breakpoint at loop-begin
  • skip one statement forward
  • reload page
  • the loop is entered, all works fine

I can close Firebug and the loop is performed properly.

The javascript code

<script type="text/javascript">
$(document).ready(function () {
   //click event of submit button
   $('#generator').click(function(){

   // GET variables
   var datafile = "my.json";
   var logo = false;

   // if checkbox is checked
   if( $('#logo').attr('checked')){
      logo = true;
   };

   // read data from json file
   $.getJSON(datafile,function(data){

   //iterate through the data-sets
   for(var i=0; i < data.length; i++) {

    // get the response from server for each data-set
    $.ajax({
       type: 'POST',
       async: false,
       cache:false,
       url: 'myfile.php',
       data: 'param1='+data[i].field1+'&param2='+data[i].field2+'&logo='+logo,
             success: function(response){

              //$('#imgdisplay').html(response);
              // alert only for debugging purposes
              alert(response);}

          }); // end of ajax-call
       };  // end of for-loop
   }  ); // end of getJSON
 }); // end of button.click
 }); // end of document.ready
</script>

(sorry for bad intented formatting)

I use a for-loop, could not get an each()-loop to work properly.

And this is the form:

<form name="settings">
   <label>Source file</label>
   <select id="datasource" name="datasource">
      <option value="extract">Extract</option> 
      <option value="filter">Filter</option>
   </select><br />
   <label>Logo</label>
   <input type="checkbox" id="logo" name="logo" value="ON"/><br />
   <p>&nbsp;</p>
   <input type="submit" value="Start Generator" id="generator" name="generator" />
</form>
<div id="imgdisplay" class="imgdisplay"></div>

What causes this strange behavior? How can I solve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:27:19+00:00Added an answer on June 13, 2026 at 3:27 pm

    Try to return false from the anonymous click method

    $('#generator').click(function(){
        ....
        return false;
    }
    

    This will ensure that the click will not post your form

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.