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 913895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:37:52+00:00 2026-05-15T17:37:52+00:00

I am doing an ajax request to a php page (‘test.php’) inside of test.php

  • 0

I am doing an ajax request to a php page (‘test.php’)
inside of test.php is

<script type="text/javascript">
 function test() {
alert('test');
}
</script>

<div id="abc">some normal content too</div>

now this function is unique to each page load, i.e it is generated via php to do different things

so, my question is how do i call that function test();

as jquery thinks the response is just text so it does not eval it

jquery has datatypes for the return

one is script the other is html

however it does not seem to have mixed.

how can i fix this?

  • 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-05-15T17:37:52+00:00Added an answer on May 15, 2026 at 5:37 pm

    The jQuery .load() function will evaluate <script> tags in the response content, but only if your call to .load() does not involve a selector to pull part of the response out before it’s inserted in the DOM.

    Thus, this call:

     $('#myContainer').load("/some/url", function() { /* ... */ });
    

    will cause any script content to be run, but this:

     $('#myContainer').load("/some/url #stuffIWant", function() { /* ... */ });
    

    will not. I don’t know why it works that way, but it does.

    If you’re loading it the first way, understand that you won’t be able to use anything defined as a global function (or a global anything) until the loading has completed. Thus:

    $('#someplace').load(url, function() { } );
    newGlobalFunction("hi");
    

    won’t work because “newGlobalFunction” won’t be defined until the asynchronous request completes. Thus, this should work:

    $('#someplace').load(url, function() {
      newGlobalFunction("hi");
    });
    

    If your ajax result is nothing but that script content, you could also consider not wrapping it in <script> tags and just eval it yourself!

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

Sidebar

Related Questions

I've got the following code: <script type=text/javascript> $(function(){ $(#AddMaps).submit(function(){ var $form = $('#AddMaps'); $.ajax({
I'm doing an ajax request through jQuery and for example, my URL is http://test.com/query.php?hello=foo
JavaScript $.ajax({ type : 'POST', url : 'post.php', data: dataString, success:function (data) { if
I am trying to fake synchronous JavaScript while doing an AJAX request. I have
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Im doing a simple ajax request like:` $.ajax({ type: 'POST', url: 'http://' + serverIP
I am doing a simple $.ajax request: $.ajax({ type: POST, url: /Run/ + param1
I'm doing a jQuery Ajax call to a PHP script that returns this string
I am making an ajax request to a php page and I cannot for
I am doing an AJAX request with Jquery and PHP what I am doing

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.