Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP and Jquery - How does AJAX work?
    primarykey
    data
    text
    <p>Hopefully this makes sense... but I am trying to write some initial ajax call to a test php page and i am getting an error within the console that reads:</p> <pre><code>Uncaught Error: Syntax error, unrecognized expression: {"projectId":"John","Project":"Some Project Name"} jquery-1.9.min.js:4 st.error jquery-1.9.min.js:4 ft jquery-1.9.min.js:4 wt jquery-1.9.min.js:4 st jquery-1.9.min.js:4 b.fn.extend.find jquery-1.9.min.js:4 b.fn.b.init jquery-1.9.min.js:3 b jquery-1.9.min.js:3 (anonymous function) download.js:27 c jquery-1.9.min.js:3 p.add jquery-1.9.min.js:3 (anonymous function) download.js:25 b.event.dispatch jquery-1.9.min.js:3 v.handle jquery-1.9.min.js:3 </code></pre> <p>This is my jquery ajax call:</p> <pre><code>$.get('test.php', {object_ID: 'kjiyu-drtfg-hjuyt-hiytr'}) .done(function(data) { console.log(data); $(data).each(function(index, element) { $('#fileList').append('&lt;option value="' + element.projectId + '"&gt;' + element.Project + '&lt;/option&gt;'); }); }); </code></pre> <p>This is my test.php page:</p> <pre><code>&lt;?php echo json_encode(array( array("projectId"=&gt;"John","Project"=&gt;"Some Project Name"), array("projectId"=&gt;"John2","Project"=&gt;"Some Project Name 2") )); ?&gt; </code></pre> <p>any advise would be greatly appreciated. In the end this will be hooked up to an actual page that looks up values from the database... I just want to get my first round going.</p> <p><strong>EDIT</strong></p> <p>I made the array change suggested but am now getting this error:</p> <pre><code>XMLHttpRequest cannot load file:///C:/Users/v-sthaff/Documents/School/Spring%202013/BIT%20286/Website/test.php?object_ID=kjiyu-drtfg-hjuyt-hiytr. Origin null is not allowed by Access-Control-Allow-Origin. jquery-1.9.min.js:5 send jquery-1.9.min.js:5 b.extend.ajax jquery-1.9.min.js:5 b.(anonymous function) jquery-1.9.min.js:5 (anonymous function) download.js:24 b.event.dispatch jquery-1.9.min.js:3 v.handle XMLHttpRequest cannot load file:///C:/Users/v-sthaff/Documents/School/Spring%202013/BIT%20286/Website/test.php?projectId=abcde-abcde-abcde-abcde. Origin null is not allowed by Access-Control-Allow-Origin. jquery-1.9.min.js:5 send jquery-1.9.min.js:5 b.extend.ajax jquery-1.9.min.js:5 b.(anonymous function) jquery-1.9.min.js:5 (anonymous function) download.js:43 b.event.dispatch jquery-1.9.min.js:3 v.handle </code></pre> <p><strong>EDIT - SOLUTION:</strong> Moving the files up to my server seemed to solve the problem as well as this updated jquery: </p> <pre><code>$.getJSON('test.php', {object_ID: 'kjiyu-drtfg-hjuyt-hiytr'}) .done(function(data) { console.log(data); $(data).each(function(index, element) { alert(element.projectId + ' ' + element.Project); $('#fileList').append('&lt;option value="' + element.projectId + '"&gt;' + element.Project + '&lt;/option&gt;'); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload